mirror of
https://github.com/Luzifer/cloudkeys-go.git
synced 2024-11-10 07:00:08 +00:00
Knut Ahlers
a1df72edc5
commitf0db1ff1f8
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:19:56 2017 +0100 Mark option as deprecated Signed-off-by: Knut Ahlers <knut@ahlers.me> commit9891df2a16
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:11:56 2017 +0100 Fix: Typo Signed-off-by: Knut Ahlers <knut@ahlers.me> commit836006de64
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:04:20 2017 +0100 Add new dependencies Signed-off-by: Knut Ahlers <knut@ahlers.me> commitd64fee60c8
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 11:55:52 2017 +0100 Replace insecure password hashing Prior this commit passwords were hashed with a static salt and using the SHA1 hashing function. This could lead to passwords being attackable in case someone gets access to the raw data stored inside the database. This commit introduces password hashing using bcrypt hashing function which addresses this issue. Old passwords are not automatically re-hashed as they are unknown. Replacing the old password scheme is not that easy and needs #10 to be solved. Therefore the old hashing scheme is kept for compatibility reason. Signed-off-by: Knut Ahlers <knut@ahlers.me> Signed-off-by: Knut Ahlers <knut@ahlers.me> closes #14 closes #15
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
// Copyright 2015 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package pkcs12
|
|
|
|
import (
|
|
"crypto/x509"
|
|
"encoding/asn1"
|
|
"errors"
|
|
)
|
|
|
|
var (
|
|
// see https://tools.ietf.org/html/rfc7292#appendix-D
|
|
oidCertTypeX509Certificate = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 9, 22, 1})
|
|
oidPKCS8ShroundedKeyBag = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 10, 1, 2})
|
|
oidCertBag = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 10, 1, 3})
|
|
)
|
|
|
|
type certBag struct {
|
|
Id asn1.ObjectIdentifier
|
|
Data []byte `asn1:"tag:0,explicit"`
|
|
}
|
|
|
|
func decodePkcs8ShroudedKeyBag(asn1Data, password []byte) (privateKey interface{}, err error) {
|
|
pkinfo := new(encryptedPrivateKeyInfo)
|
|
if err = unmarshal(asn1Data, pkinfo); err != nil {
|
|
return nil, errors.New("pkcs12: error decoding PKCS#8 shrouded key bag: " + err.Error())
|
|
}
|
|
|
|
pkData, err := pbDecrypt(pkinfo, password)
|
|
if err != nil {
|
|
return nil, errors.New("pkcs12: error decrypting PKCS#8 shrouded key bag: " + err.Error())
|
|
}
|
|
|
|
ret := new(asn1.RawValue)
|
|
if err = unmarshal(pkData, ret); err != nil {
|
|
return nil, errors.New("pkcs12: error unmarshaling decrypted private key: " + err.Error())
|
|
}
|
|
|
|
if privateKey, err = x509.ParsePKCS8PrivateKey(pkData); err != nil {
|
|
return nil, errors.New("pkcs12: error parsing PKCS#8 private key: " + err.Error())
|
|
}
|
|
|
|
return privateKey, nil
|
|
}
|
|
|
|
func decodeCertBag(asn1Data []byte) (x509Certificates []byte, err error) {
|
|
bag := new(certBag)
|
|
if err := unmarshal(asn1Data, bag); err != nil {
|
|
return nil, errors.New("pkcs12: error decoding cert bag: " + err.Error())
|
|
}
|
|
if !bag.Id.Equal(oidCertTypeX509Certificate) {
|
|
return nil, NotImplementedError("only X509 certificates are supported")
|
|
}
|
|
return bag.Data, nil
|
|
}
|