decode b32 first
This commit is contained in:
parent
329039efb3
commit
9ce706684c
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
|
"encoding/base32"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
@ -48,20 +49,28 @@ type EdDSASignature struct {
|
|||||||
S [256 / 8]byte `json:"s"`
|
S [256 / 8]byte `json:"s"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// following gnunet/src/util/crypto_rsa.c
|
// following gnunet/src/json/json_helper.c and gnunet/src/util/crypto_rsa.c
|
||||||
func (ep *EncodedRSAPublicKey) Decode() (p rsa.PublicKey, e error) {
|
func (ep *EncodedRSAPublicKey) Decode() (p rsa.PublicKey, e error) {
|
||||||
buf := []byte(*ep)
|
var buf []byte
|
||||||
|
|
||||||
|
// 1. decode base32
|
||||||
|
_, e = base32.StdEncoding.Decode(buf, *ep)
|
||||||
|
if e != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. parse header
|
||||||
if len(buf) < 4 {
|
if len(buf) < 4 {
|
||||||
e = fmt.Errorf("byte array too small for RSA public key header")
|
e = fmt.Errorf("byte array too small for RSA public key header")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
modulus_length, public_exponent_length := binary.BigEndian.Uint16(buf[0:]), binary.BigEndian.Uint16(buf[2:])
|
modulus_length, public_exponent_length := binary.BigEndian.Uint16(buf[0:]), binary.BigEndian.Uint16(buf[2:])
|
||||||
if len(buf[4:]) != int(modulus_length)+int(public_exponent_length) {
|
if len(buf[4:]) != int(modulus_length)+int(public_exponent_length) {
|
||||||
e = fmt.Errorf("byte array has wrong size according to encoded length's for modulus and public exponent")
|
e = fmt.Errorf("byte array has wrong size according to encoded length's for modulus and public exponent")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. parse RSA public key
|
||||||
// BUG! This is most likely wrong.
|
// BUG! This is most likely wrong.
|
||||||
// Consult _gcry_mpi_set_buffer from libgcrypt-1.9.4/mpi/mpicoder.c
|
// Consult _gcry_mpi_set_buffer from libgcrypt-1.9.4/mpi/mpicoder.c
|
||||||
buf = buf[4:]
|
buf = buf[4:]
|
||||||
|
Loading…
Reference in New Issue
Block a user