diff --git a/cmd/taler-auditor-offline-signing/main.go b/cmd/taler-auditor-offline-signing/main.go index c997165..f9050e1 100644 --- a/cmd/taler-auditor-offline-signing/main.go +++ b/cmd/taler-auditor-offline-signing/main.go @@ -2,6 +2,7 @@ package main import ( "crypto/rsa" + "encoding/base32" "encoding/binary" "fmt" "math/big" @@ -48,20 +49,28 @@ type EdDSASignature struct { 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) { - 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 { e = fmt.Errorf("byte array too small for RSA public key header") return } - 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) { e = fmt.Errorf("byte array has wrong size according to encoded length's for modulus and public exponent") return } + // 3. parse RSA public key // BUG! This is most likely wrong. // Consult _gcry_mpi_set_buffer from libgcrypt-1.9.4/mpi/mpicoder.c buf = buf[4:]