Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/FeiniuBus/signer
Browse files Browse the repository at this point in the history
  • Loading branch information
gotoxu committed Nov 20, 2017
2 parents fc0a804 + cd151e0 commit 11bb3c1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rsa_cert_issuor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package signer

type RSACertIssuor interface {
GetRootCert() RSACert
Issue(subject *x509Subject) (RSACert, error)
Issue(subject *X509Subject) (RSACert, error)
}
6 changes: 4 additions & 2 deletions rsa_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
var store RSAStore

func DISABLETest_RSAServer(t *testing.T) {

root, err := Parsex509RSACert(getRootCA(), getRootKey())
if err != nil {
t.Fatal(err)
}

factory := NewRSAStoreFactory("test", "polaris/Certificates", root, GetDefaultSubject())
store, err := factory.Create(x509RSAStore_OneToMany)
store, err := factory.Create(X509RSAStore_OneToMany)
if err != nil {
t.Fatal(err)
}
Expand All @@ -36,13 +37,14 @@ func DISABLETest_RSAServer(t *testing.T) {
}

func DISABLETest_RSAServerParallel(t *testing.T) {

root, err := Parsex509RSACert(getRootCA(), getRootKey())
if err != nil {
t.Fatal(err)
}

factory := NewRSAStoreFactory("test", "polaris/Certificates", root, GetDefaultSubject())
store, err := factory.Create(x509RSAStore_OneToMany)
store, err := factory.Create(X509RSAStore_OneToMany)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions x509_rsa_cert_issuor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (issuor *x509RSACertIssuor) GetRootCert() RSACert {
return issuor.root
}

func (issuor *x509RSACertIssuor) Issue(subject *x509Subject) (RSACert, error) {
func (issuor *x509RSACertIssuor) Issue(subject *X509Subject) (RSACert, error) {
cer := issuor.buildCertificate(subject)

ca, err := x509.CreateCertificate(rand.Reader, cer, issuor.GetRootCert().GetCertificate(), &issuor.priKey.PublicKey, issuor.GetRootCert().GetPrivateKey())
Expand Down Expand Up @@ -54,7 +54,7 @@ func (issuor *x509RSACertIssuor) Issue(subject *x509Subject) (RSACert, error) {
return cert, nil
}

func (issuor *x509RSACertIssuor) buildCertificate(subject *x509Subject) *x509.Certificate {
func (issuor *x509RSACertIssuor) buildCertificate(subject *X509Subject) *x509.Certificate {

return &x509.Certificate{
SerialNumber: big.NewInt(rd.Int63()), //证书序列号
Expand Down
18 changes: 9 additions & 9 deletions x509_rsa_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

type x509RSAOneToManyStore struct {
rootCert RSACert
subject *x509Subject
subject *X509Subject
priKey *rsa.PrivateKey
expire time.Time
mu sync.Mutex
Expand Down Expand Up @@ -94,21 +94,21 @@ func (s *x509RSAOneToManyStore) Certificate(clientID string) (RSADescriptor, err
return descriptor, nil
}

type x509RSAStoreMode int
type X509RSAStoreMode int

const (
_ x509RSAStoreMode = iota
x509RSAStore_OneToMany
_ X509RSAStoreMode = iota
X509RSAStore_OneToMany
)

type RSAStoreFactory struct {
rootCert RSACert
subject *x509Subject
subject *X509Subject
tag string
bucket string
}

func NewRSAStoreFactory(tag string, bucket string, rootCert RSACert, subject *x509Subject) *RSAStoreFactory {
func NewRSAStoreFactory(tag string, bucket string, rootCert RSACert, subject *X509Subject) *RSAStoreFactory {
return &RSAStoreFactory{
rootCert: rootCert,
subject: subject,
Expand All @@ -117,7 +117,7 @@ func NewRSAStoreFactory(tag string, bucket string, rootCert RSACert, subject *x5
}
}

func NewRSAStoreFactoryFrom(tag string, bucket string, rootPriKeyUrl string, rootCertUrl string, subject *x509Subject) (*RSAStoreFactory, error) {
func NewRSAStoreFactoryFrom(tag string, bucket string, rootPriKeyUrl string, rootCertUrl string, subject *X509Subject) (*RSAStoreFactory, error) {
rootPriKeyAccessor, err := ParseURI(rootPriKeyUrl)
if err != nil {
return nil, err
Expand All @@ -144,8 +144,8 @@ func NewRSAStoreFactoryFrom(tag string, bucket string, rootPriKeyUrl string, roo
return NewRSAStoreFactory(tag, bucket, cert, subject), nil
}

func (factory *RSAStoreFactory) Create(mode x509RSAStoreMode) (RSAStore, error) {
if mode == x509RSAStore_OneToMany {
func (factory *RSAStoreFactory) Create(mode X509RSAStoreMode) (RSAStore, error) {
if mode == X509RSAStore_OneToMany {
return &x509RSAOneToManyStore{
rootCert: factory.rootCert,
subject: factory.subject,
Expand Down
6 changes: 3 additions & 3 deletions x509_subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"
)

type x509Subject struct {
type X509Subject struct {
Country []string
Orianization []string
OrianizationalUnit []string
Expand All @@ -19,8 +19,8 @@ type x509Subject struct {
IsRoot bool
}

func GetDefaultSubject() *x509Subject {
return &x509Subject{
func GetDefaultSubject() *X509Subject {
return &X509Subject{
Country: []string{"CN"},
Orianization: []string{"FEINIUBUS"},
OrianizationalUnit: []string{"CITADEL"},
Expand Down

0 comments on commit 11bb3c1

Please sign in to comment.