}
func d(r []byte, target, value string) (err error) {
- v, err := strconv.Atoi64(value)
+ v, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return
}
func (r *prng) Read(p []byte) (n int, err error) {
h := sha1.New()
h.Write(r.state)
- r.state = h.Sum()
+ r.state = h.Sum(nil)
n = copy(p, r.state)
return
}
+++ /dev/null
-diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/signature.go
---- a/src/pkg/crypto/openpgp/packet/signature.go Thu Nov 24 08:51:47 2011 -0800
-+++ b/src/pkg/crypto/openpgp/packet/signature.go Fri Dec 02 01:56:00 2011 +0100
-@@ -144,14 +144,21 @@
- // parseSignatureSubpackets parses subpackets of the main signature packet. See
- // RFC 4880, section 5.2.3.1.
- func parseSignatureSubpackets(sig *Signature, subpackets []byte, isHashed bool) (err error) {
-+ hasCreationTime := false
-+
- for len(subpackets) > 0 {
-- subpackets, err = parseSignatureSubpacket(sig, subpackets, isHashed)
-+ var packetType signatureSubpacketType
-+
-+ packetType, subpackets, err = parseSignatureSubpacket(sig, subpackets, isHashed)
- if err != nil {
- return
- }
-+ if packetType == creationTimeSubpacket {
-+ hasCreationTime = true
-+ }
- }
-
-- if sig.CreationTime == 0 {
-+ if isHashed && !hasCreationTime {
- err = error_.StructuralError("no creation time in signature")
- }
-
-@@ -173,11 +180,10 @@
- )
-
- // parseSignatureSubpacket parses a single subpacket. len(subpacket) is >= 1.
--func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (rest []byte, err error) {
-+func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (packetType signatureSubpacketType, rest []byte, err error) {
- // RFC 4880, section 5.2.3.1
- var (
- length uint32
-- packetType signatureSubpacketType
- isCritical bool
- )
- switch {
-diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/private_key.go
---- a/src/pkg/crypto/openpgp/packet/private_key.go Thu Nov 24 08:51:47 2011 -0800
-+++ b/src/pkg/crypto/openpgp/packet/private_key.go Tue Nov 29 17:21:15 2011 +0100
-@@ -27,7 +27,7 @@
+diff -r 7ec969250bfc src/pkg/crypto/openpgp/packet/private_key.go
+--- a/src/pkg/crypto/openpgp/packet/private_key.go Tue Dec 27 09:49:19 2011 -0500
++++ b/src/pkg/crypto/openpgp/packet/private_key.go Fri Dec 30 22:57:08 2011 +0100
+@@ -28,7 +28,7 @@
encryptedData []byte
cipher CipherFunction
s2k func(out, in []byte)
sha1Checksum bool
iv []byte
}
-@@ -39,6 +39,13 @@
+@@ -40,6 +40,13 @@
return pk
}
-+func NewDSAPrivateKey(currentTimeSecs uint32, priv *dsa.PrivateKey, isSubkey bool) *PrivateKey {
++func NewDSAPrivateKey(currentTime time.Time, priv *dsa.PrivateKey, isSubkey bool) *PrivateKey {
+ pk := new(PrivateKey)
-+ pk.PublicKey = *NewDSAPublicKey(currentTimeSecs, &priv.PublicKey, isSubkey)
++ pk.PublicKey = *NewDSAPublicKey(currentTime, &priv.PublicKey, isSubkey)
+ pk.PrivateKey = priv
+ return pk
+}
func (pk *PrivateKey) parse(r io.Reader) (err error) {
err = (&pk.PublicKey).parse(r)
if err != nil {
-@@ -120,6 +127,8 @@
+@@ -121,6 +128,8 @@
switch priv := pk.PrivateKey.(type) {
case *rsa.PrivateKey:
err = serializeRSAPrivateKey(privateKeyBuf, priv)
default:
err = error_.InvalidArgumentError("non-RSA private key")
}
-@@ -171,6 +180,10 @@
+@@ -172,6 +181,10 @@
return writeBig(w, priv.Precomputed.Qinv)
}
// Decrypt decrypts an encrypted private key using a passphrase.
func (pk *PrivateKey) Decrypt(passphrase []byte) error {
if !pk.Encrypted {
-diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/public_key.go
---- a/src/pkg/crypto/openpgp/packet/public_key.go Thu Nov 24 08:51:47 2011 -0800
-+++ b/src/pkg/crypto/openpgp/packet/public_key.go Tue Nov 29 17:21:15 2011 +0100
-@@ -52,6 +52,23 @@
+diff -r 7ec969250bfc src/pkg/crypto/openpgp/packet/public_key.go
+--- a/src/pkg/crypto/openpgp/packet/public_key.go Tue Dec 27 09:49:19 2011 -0500
++++ b/src/pkg/crypto/openpgp/packet/public_key.go Fri Dec 30 22:57:08 2011 +0100
+@@ -53,6 +53,23 @@
return pk
}
+// NewDSAPublicKey returns a PublicKey that wraps the given rsa.PublicKey.
-+func NewDSAPublicKey(creationTimeSecs uint32, pub *dsa.PublicKey, isSubkey bool) *PublicKey {
++func NewDSAPublicKey(creationTime time.Time, pub *dsa.PublicKey, isSubkey bool) *PublicKey {
+ pk := &PublicKey{
-+ CreationTime: creationTimeSecs,
++ CreationTime: creationTime,
+ PubKeyAlgo: PubKeyAlgoDSA,
+ PublicKey: pub,
+ IsSubkey: isSubkey,
-diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/signature.go
---- a/src/pkg/crypto/openpgp/packet/signature.go Thu Nov 24 08:51:47 2011 -0800
-+++ b/src/pkg/crypto/openpgp/packet/signature.go Wed Nov 30 23:44:34 2011 +0100
-@@ -163,7 +163,7 @@
+diff -r 7ec969250bfc src/pkg/crypto/openpgp/packet/signature.go
+--- a/src/pkg/crypto/openpgp/packet/signature.go Tue Dec 27 09:49:19 2011 -0500
++++ b/src/pkg/crypto/openpgp/packet/signature.go Fri Dec 30 22:56:55 2011 +0100
+@@ -164,7 +164,7 @@
const (
creationTimeSubpacket signatureSubpacketType = 2
signatureExpirationSubpacket signatureSubpacketType = 3
prefSymmetricAlgosSubpacket signatureSubpacketType = 11
issuerSubpacket signatureSubpacketType = 16
prefHashAlgosSubpacket signatureSubpacketType = 21
-@@ -235,7 +235,7 @@
+@@ -225,11 +225,7 @@
+ return
+ }
+ t := binary.BigEndian.Uint32(subpacket)
+- if t == 0 {
+- sig.CreationTime = time.Time{}
+- } else {
+- sig.CreationTime = time.Unix(int64(t), 0)
+- }
++ sig.CreationTime = time.Unix(int64(t), 0)
+ case signatureExpirationSubpacket:
+ // Signature expiration time, section 5.2.3.10
+ if !isHashed {
+@@ -241,7 +237,7 @@
}
sig.SigLifetimeSecs = new(uint32)
*sig.SigLifetimeSecs = binary.BigEndian.Uint32(subpacket)
// Key expiration time, section 5.2.3.6
if !isHashed {
return
-@@ -541,10 +541,7 @@
-
- func (sig *Signature) buildSubpackets() (subpackets []outputSubpacket) {
- creationTime := make([]byte, 4)
-- creationTime[0] = byte(sig.CreationTime >> 24)
-- creationTime[1] = byte(sig.CreationTime >> 16)
-- creationTime[2] = byte(sig.CreationTime >> 8)
-- creationTime[3] = byte(sig.CreationTime)
-+ binary.BigEndian.PutUint32(creationTime, sig.CreationTime)
- subpackets = append(subpackets, outputSubpacket{true, creationTimeSubpacket, false, creationTime})
-
- if sig.IssuerKeyId != nil {
-@@ -553,5 +550,59 @@
+@@ -556,5 +552,59 @@
subpackets = append(subpackets, outputSubpacket{true, issuerSubpacket, false, keyId})
}
func Id(c *Signed) string {
h := sha1.New()
h.Write(c.Body)
- return fmt.Sprintf("%040X", h.Sum())
+ return fmt.Sprintf("%040X", h.Sum(nil))
}
// Parse an epoint document without checking the signature and format details
fv.SetString(val)
case "int":
var val int64
- val, err = strconv.Atoi64(s)
+ val, err = strconv.ParseInt(s, 10, 64)
fv.SetInt(val)
case "date":
var val int64
case "text":
val = formatString(fv.String())
case "int":
- val = strconv.Itoa64(fv.Int())
+ val = strconv.FormatInt(fv.Int(), 10)
case "date":
val = formatDate(fv.Int())
case "ids":
if err != nil {
return 0, err
}
- return t.Seconds(), nil
+ return t.Unix(), nil
}
func formatDate(i int64) string {
- return time.SecondsToUTC(i).Format(time.RFC3339)
+ return time.Unix(i,0).Format(time.RFC3339)
}
func getLine(data []byte) (line, rest []byte) {
"fmt"
"io"
"math/big"
+ "time"
)
// TODO: keep denomination only in issuer key?
loop:
h := sha1.New()
h.Write(r)
- r = h.Sum()
+ r = h.Sum(nil)
x.SetBytes(r)
// TODO: zero out r and h ?
if x.Sign() == 0 || x.Cmp(priv.Q) >= 0 {
// New returns an openpgp.Entity that contains a fresh DSA private key with a
// single identity composed of the given full name, comment and email, any of
// which may be empty but must not contain any of "()<>\x00".
-func New(priv *dsa.PrivateKey, currentTimeSecs int64, name, comment, email string) (e *openpgp.Entity, err error) {
+func New(priv *dsa.PrivateKey, t time.Time, name, comment, email string) (e *openpgp.Entity, err error) {
uid := packet.NewUserId(name, comment, email)
if uid == nil {
return nil, fmt.Errorf("NewEntity: invalid argument: user id field contained invalid characters")
}
- t := uint32(currentTimeSecs)
e = &openpgp.Entity{
PrimaryKey: packet.NewDSAPublicKey(t, &priv.PublicKey, false /* not a subkey */ ),
PrivateKey: packet.NewDSAPrivateKey(t, priv, false /* not a subkey */ ),
// Issuer generates a key for obligation issuer clients from random seed r
func Issuer(r []byte, denomination string) (e *openpgp.Entity, err error) {
- return New(DsaKey(r), 0, "Issuer", denomination, "")
+ return New(DsaKey(r), time.Unix(0,0), "Issuer", denomination, "")
}
// Holder generates a key for obligation holder clients from random seed r
func Holder(r []byte, issuer, denomination string) (e *openpgp.Entity, err error) {
- return New(DsaKey(r), 0, "Holder of "+issuer, denomination, "")
+ return New(DsaKey(r), time.Unix(0,0), "Holder of "+issuer, denomination, "")
}
// Key id (fingerprint)
t.Errorf("gen dsa key failed: %s", err)
return
}
- priv, err := New(key, time.Seconds(), "a", "b", "c")
+ priv, err := New(key, time.Now(), "a", "b", "c")
if err != nil {
t.Errorf("New failed: %s", err)
} else {
func NewDebitCert(draftid string, draft *document.Draft) (*document.DebitCert, error) {
cert := new(document.DebitCert)
cert.Holder = draft.Drawer
- cert.Date = time.Seconds()
+ cert.Date = time.Now().Unix()
cert.Denomination = "epoint"
cert.Issuer = draft.Issuer
cert.AuthorizedBy = draft.AuthorizedBy
cert := new(document.CreditCert)
// TODO: get from old cert instead?
cert.Holder = dcert.Beneficiary
- cert.Date = time.Seconds()
+ cert.Date = time.Now().Unix()
// TODO: get these from the cert holder pubkey
cert.Denomination = "epoint"
cert.Issuer = draft.Issuer