-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement ecdsa keyfile signing support
- Loading branch information
Showing
10 changed files
with
317 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package assuan | ||
|
||
import ( | ||
"crypto" | ||
"crypto/ecdsa" | ||
"crypto/elliptic" | ||
"crypto/rsa" | ||
"fmt" | ||
"math/big" | ||
) | ||
|
||
// readKeyData returns information about the given key in a libgcrypt-specific | ||
// format | ||
func readKeyData(pub crypto.PublicKey) (string, error) { | ||
switch k := pub.(type) { | ||
case *rsa.PublicKey: | ||
n := k.N.Bytes() | ||
nLen := len(n) // need the actual byte length before munging | ||
n = percentEncodeSExp(n) // ugh | ||
ei := new(big.Int) | ||
ei.SetInt64(int64(k.E)) | ||
e := ei.Bytes() | ||
// prefix the key with a null byte for compatibility | ||
return fmt.Sprintf("D (10:public-key(3:rsa(1:n%d:\x00%s)(1:e%d:%s)))\n", | ||
nLen+1, n, len(e), e), nil | ||
case *ecdsa.PublicKey: | ||
switch k.Curve { | ||
case elliptic.P256(): | ||
q := elliptic.Marshal(k.Curve, k.X, k.Y) | ||
return fmt.Sprintf( | ||
"D (10:public-key(3:ecc(5:curve10:NIST P-256)(1:q%d:%s)))\n", | ||
len(q), q), nil | ||
default: | ||
return "", fmt.Errorf("unsupported curve: %T", k.Curve) | ||
} | ||
default: | ||
return "", nil | ||
} | ||
} |
Binary file added
BIN
+298 Bytes
internal/assuan/testdata/private-subkeys/foo-sub-ecdsa@example.com.sub-ecdsa.gpg
Binary file not shown.
Binary file added
BIN
+1.82 KB
internal/assuan/testdata/private-subkeys/foo-sub@example.com.sub-rsa.gpg
Binary file not shown.
Binary file added
BIN
+1.81 KB
internal/assuan/testdata/private-subkeys/foo@example.com.primary-rsa.gpg
Binary file not shown.
Oops, something went wrong.