Remove unnecessary custom signature encoding
This commit is contained in:
parent
e94ea17dad
commit
9b46d5d5bf
2 changed files with 1 additions and 39 deletions
|
@ -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)
|
||||
|
|
|
@ -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[:])
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue