diff --git a/libgm/crypto/encode.go b/libgm/crypto/encode.go index 74be9f2..2be921a 100644 --- a/libgm/crypto/encode.go +++ b/libgm/crypto/encode.go @@ -11,22 +11,6 @@ import ( var SequenceOne = []int{1, 2, 840, 10045, 2, 1} var SequenceTwo = []int{1, 2, 840, 10045, 3, 1, 7} -func EncodeBNA(a []byte) []byte { - b := 0 - for b < len(a) && a[b] == 0 { - b++ - } - - c := 0 - if b < len(a) && (a[b]&128) == 128 { - c = 1 - } - - d := make([]byte, len(a)-b+c) - copy(d[c:], a[b:]) - return d -} - func EncodeValues(a *[]byte, b []int) { *a = append(*a, 6) idx := len(*a) diff --git a/libgm/crypto/signer.go b/libgm/crypto/signer.go index b662772..4d8bfdd 100644 --- a/libgm/crypto/signer.go +++ b/libgm/crypto/signer.go @@ -26,27 +26,5 @@ func (t *JWK) SignRequest(requestId string, timestamp int64) (string, error) { func (t *JWK) sign(key *ecdsa.PrivateKey, msg []byte) ([]byte, error) { hash := sha256.Sum256(msg) - r, s, err := ecdsa.Sign(rand.Reader, key, hash[:]) - if err != nil { - return nil, err - } - - rBytes := r.Bytes() - sBytes := s.Bytes() - - rBytes = EncodeBNA(rBytes) - sBytes = EncodeBNA(sBytes) - - sigLen := len(rBytes) + len(sBytes) + 6 // 2 bytes for each sequence tag and 2 bytes for each length field - sig := make([]byte, sigLen) - sig[0] = 48 - sig[1] = byte(sigLen - 2) - sig[2] = 2 - sig[3] = byte(len(rBytes)) - copy(sig[4:], rBytes) - sig[4+len(rBytes)] = 2 - sig[5+len(rBytes)] = byte(len(sBytes)) - copy(sig[6+len(rBytes):], sBytes) - - return sig, nil + return ecdsa.SignASN1(rand.Reader, key, hash[:]) }