Skip to content

Commit

Permalink
Fix creation date conversion issue
Browse files Browse the repository at this point in the history
Thanks to @yougg for report
Close #4
  • Loading branch information
Pavel Chernykh committed Sep 19, 2017
1 parent 9b76ac5 commit 63bed89
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
13 changes: 12 additions & 1 deletion common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package keystore

import "encoding/binary"
import (
"encoding/binary"
"time"
)

const magic uint32 = 0xfeedfeed
const (
Expand Down Expand Up @@ -30,3 +33,11 @@ func zeroing(s []byte) {
s[i] = 0
}
}

func millisecondsToTime(ms int64) time.Time {
return time.Unix(0, ms*int64(time.Millisecond))
}

func timeToMilliseconds(t time.Time) int64 {
return t.UnixNano() / int64(time.Millisecond)
}
5 changes: 2 additions & 3 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"hash"
"io"
"time"
)

const defaultCertificateType = "X509"
Expand Down Expand Up @@ -164,7 +163,7 @@ func (ksd *keyStoreDecoder) readPrivateKeyEntry(version uint32, password []byte)
if err != nil {
return nil, err
}
creationDateTime := time.Unix(int64(creationDateTimeStamp), 0)
creationDateTime := millisecondsToTime(int64(creationDateTimeStamp))
privateKeyEntry := PrivateKeyEntry{
Entry: Entry{
CreationDate: creationDateTime,
Expand All @@ -184,7 +183,7 @@ func (ksd *keyStoreDecoder) readTrustedCertificateEntry(version uint32) (*Truste
if err != nil {
return nil, err
}
creationDateTime := time.Unix(int64(creationDateTimeStamp), 0)
creationDateTime := millisecondsToTime(int64(creationDateTimeStamp))
trustedCertificateEntry := TrustedCertificateEntry{
Entry: Entry{
CreationDate: creationDateTime,
Expand Down
4 changes: 2 additions & 2 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (kse *keyStoreEncoder) writeTrustedCertificateEntry(alias string, tce *Trus
if err != nil {
return err
}
err = kse.writeUint64(uint64(tce.CreationDate.Unix()))
err = kse.writeUint64(uint64(timeToMilliseconds(tce.CreationDate)))
if err != nil {
return err
}
Expand All @@ -139,7 +139,7 @@ func (kse *keyStoreEncoder) writePrivateKeyEntry(alias string, pke *PrivateKeyEn
if err != nil {
return err
}
err = kse.writeUint64(uint64(pke.CreationDate.Unix()))
err = kse.writeUint64(uint64(timeToMilliseconds(pke.CreationDate)))
if err != nil {
return err
}
Expand Down
Binary file modified examples/compare/keystore.jks
Binary file not shown.

0 comments on commit 63bed89

Please sign in to comment.