update the codebase to latest go src (time, hash, strconv)
authornsz <nsz@port70.net>
Fri, 30 Dec 2011 22:26:04 +0000 (23:26 +0100)
committernsz <nsz@port70.net>
Fri, 30 Dec 2011 22:26:04 +0000 (23:26 +0100)
cmd/epoint-client/epoint-client.go
cmd/genpqg/genpqg.go
patches/creationtime.diff [deleted file]
patches/dsa.diff
patches/sig.diff
pkg/document/document.go
pkg/key/key.go
pkg/key/key_test.go
pkg/server/server.go

index 71bbe04..8a129c6 100644 (file)
@@ -117,7 +117,7 @@ func k(r []byte, cmd, arg string) (err error) {
 }
 
 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
        }
index 0bd80e3..f26f18e 100644 (file)
@@ -27,7 +27,7 @@ var r = &prng{[]byte{
 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
 }
diff --git a/patches/creationtime.diff b/patches/creationtime.diff
deleted file mode 100644 (file)
index 452aa61..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-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 {
index b1c7629..1970704 100644 (file)
@@ -1,7 +1,7 @@
-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)
@@ -10,13 +10,13 @@ diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/private_key.go
        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
 +}
@@ -24,7 +24,7 @@ diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/private_key.go
  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)
@@ -33,7 +33,7 @@ diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/private_key.go
        default:
                err = error_.InvalidArgumentError("non-RSA private key")
        }
-@@ -171,6 +180,10 @@
+@@ -172,6 +181,10 @@
        return writeBig(w, priv.Precomputed.Qinv)
  }
  
@@ -44,17 +44,17 @@ diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/private_key.go
  // 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,
index 3aa7e85..d3c49b5 100644 (file)
@@ -1,7 +1,7 @@
-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
@@ -10,7 +10,20 @@ diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/signature.go
        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)
@@ -19,19 +32,7 @@ diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/signature.go
                // 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})
        }
  
index 1b7181d..3deaef2 100644 (file)
@@ -207,7 +207,7 @@ func cleanBody(s []byte) []byte {
 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
@@ -469,7 +469,7 @@ func parseStruct(v reflect.Value, fields map[string]string, seen map[string]bool
                        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
@@ -559,7 +559,7 @@ func formatStruct(v reflect.Value, doc *Document) (err error) {
                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":
@@ -675,11 +675,11 @@ func parseDate(s string) (int64, error) {
        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) {
index d02d91c..6f2a322 100644 (file)
@@ -26,6 +26,7 @@ import (
        "fmt"
        "io"
        "math/big"
+       "time"
 )
 
 // TODO: keep denomination only in issuer key?
@@ -47,7 +48,7 @@ func DsaKey(r []byte) *dsa.PrivateKey {
 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 {
@@ -71,12 +72,11 @@ func RandomDsaKey() (priv *dsa.PrivateKey, err error) {
 // 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 */ ),
@@ -122,11 +122,11 @@ func Parse(d []byte) (e *openpgp.Entity, err error) {
 
 // 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)
index 0226d12..65651a8 100644 (file)
@@ -29,7 +29,7 @@ func TestKey(t *testing.T) {
                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 {
index 9822a64..e3c3d29 100644 (file)
@@ -218,7 +218,7 @@ func ParseDebitCert(d []byte) (cert *document.DebitCert, certid string, err erro
 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
@@ -278,7 +278,7 @@ func NewCreditCert(draftid string, draft *document.Draft, dcertid string, dcert
        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