Documentation ¶
Index ¶
- func B64Decode(str string) (buf []byte, err error)
- func B64Encode(buf []byte) string
- func ConvertJSONFileToJSONString(jsonFileLocation string) string
- func CreateToken(cert []byte, key []byte, body []byte) (string, error)
- func DERCertToPEM(der []byte) []byte
- func DecodeToken(token string) (*x509.Certificate, string, string, error)
- func ECDSASignDirect(signKey interface{}, msg []byte) (*big.Int, *big.Int, error)
- func FileExists(name string) bool
- func GenECDSAToken(cert []byte, key []byte, body []byte) (string, error)
- func GenNumber(numlen *big.Int) *big.Int
- func GenRSAToken(cert []byte, key []byte, body []byte) (string, error)
- func GenRootKey(csp bccsp.BCCSP) (bccsp.Key, error)
- func GetAttributes(jsonString string) map[string]string
- func GetBCCSP(cfg interface{}) (bccsp.BCCSP, error)
- func GetDB(driver string, dbPath string) (*sqlx.DB, error)
- func GetDefaultHomeDir() string
- func GetECPrivateKey(raw []byte) (*ecdsa.PrivateKey, error)
- func GetEnrollmentIDFromPEM(cert []byte) (string, error)
- func GetEnrollmentIDFromX509Certificate(cert *x509.Certificate) string
- func GetPrivateKey(privateKey string) (*rsa.PrivateKey, error)
- func GetPublicKey(publicKey string) (*rsa.PublicKey, error)
- func GetRSAPrivateKey(raw []byte) (*rsa.PrivateKey, error)
- func GetX509CertificateFromPEM(cert []byte) (*x509.Certificate, error)
- func HTTPRequestToString(req *http.Request) string
- func HTTPResponseToString(resp *http.Response) string
- func MakeFileAbs(file, dir string) (string, error)
- func Marshal(from interface{}, what string) ([]byte, error)
- func NewSelfSignedCert() ([]byte, interface{}, error)
- func RSASign(message []byte, shaAlgo string, rsaPrivateKey *rsa.PrivateKey) string
- func RSASignJSON(jsonString string, signatureJSON string, rsaPrivateKey *rsa.PrivateKey, ...) string
- func RSAVerifySig(publicKey *rsa.PublicKey, hashAlgo string, signature string, message []byte) bool
- func RandomString(n int) string
- func ReadFile(file string) ([]byte, error)
- func ReadJSONAsMapFile(configFileLocation string, stringLocator string) string
- func ReadJSONAsMapString(jsonString string, stringLocator string) string
- func RemoveQuotes(str string) string
- func SignECMessage(JSONString string, signatureJSON string) string
- func StrContained(str string, strs []string) bool
- func Unmarshal(from []byte, to interface{}, what string) error
- func ValidateCert(cert *x509.Certificate) bool
- func VerifyECMessage(JSONString string, signatureString string) bool
- func VerifyECMessageImpl(JSONString string, signatureString string, pub *ecdsa.PublicKey) bool
- func VerifyMessage(jsonString string, signatureString string) bool
- func VerifyRSAMessageImpl(jsonString string, signatureString string, publicKey *rsa.PublicKey) bool
- func VerifyToken(token string, body []byte) (*x509.Certificate, error)
- func WriteFile(file string, buf []byte, perm os.FileMode) error
- func WriteJSONAsMapToFile(stringLocator string, value string, filePath string) error
- func WriteJSONAsMapToString(jsonString string, stringLocator string, value string) string
- func WriteJSONToString(jsonString string, valueMap map[string]string) string
- func WriteToJSON(filePath string, cotentToAppend string)
- type CertificateSpec
- func (spec *CertificateSpec) GetCertificateType() float64
- func (spec *CertificateSpec) GetCommonName() string
- func (spec *CertificateSpec) GetCountry() string
- func (spec *CertificateSpec) GetExtensions() *[]pkix.Extension
- func (spec *CertificateSpec) GetLocality() string
- func (spec *CertificateSpec) GetNotAfter() time.Time
- func (spec *CertificateSpec) GetNotBefore() time.Time
- func (spec *CertificateSpec) GetOrganization() string
- func (spec *CertificateSpec) GetOrganizationalUnit() string
- func (spec *CertificateSpec) GetPublicKey() interface{}
- func (spec *CertificateSpec) GetSerialNumber() *big.Int
- func (spec *CertificateSpec) GetSignatureAlgorithm() x509.SignatureAlgorithm
- func (spec *CertificateSpec) GetState() string
- func (spec *CertificateSpec) GetSubjectKeyID() *[]byte
- func (spec *CertificateSpec) GetUsage() x509.KeyUsage
- type ECDSASignature
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertJSONFileToJSONString ¶
ConvertJSONFileToJSONString converts a file of json format to a json string
func CreateToken ¶
CreateToken creates a JWT-like token. In a normal JWT token, the format of the token created is:
<algorithm,claims,signature>
where each part is base64-encoded string separated by a period. In this JWT-like token, there are two differences:
- the claims section is a certificate, so the format is: <certificate,signature>
- the signature uses the private key associated with the certificate, and the signature is across both the certificate and the "body" argument, which is the body of an HTTP request, though could be any arbitrary bytes.
@param cert The pem-encoded certificate @param key The pem-encoded key @param body The body of an HTTP request
func DecodeToken ¶
DecodeToken extracts an X509 certificate and base64 encoded signature from a token
func ECDSASignDirect ¶
ECDSASignDirect signs the message msg and returns R,S using ECDSA
func GenECDSAToken ¶
GenECDSAToken signs the http body and cert with ECDSA using EC private key
func GenRSAToken ¶
GenRSAToken signs the http body and cert with RSA using RSA private key
func GenRootKey ¶
GenRootKey generates a new root key
func GetAttributes ¶
GetAttributes get attributes from jsonString @jsonString : jsonString containing Attributes @ returns : map containing attribute name as Key and Attribute Value as value
func GetDefaultHomeDir ¶
func GetDefaultHomeDir() string
GetDefaultHomeDir returns the default cop home
func GetECPrivateKey ¶
func GetECPrivateKey(raw []byte) (*ecdsa.PrivateKey, error)
GetECPrivateKey get *ecdsa.PrivateKey from key pem
func GetEnrollmentIDFromPEM ¶
GetEnrollmentIDFromPEM returns the EnrollmentID from a PEM buffer
func GetEnrollmentIDFromX509Certificate ¶
func GetEnrollmentIDFromX509Certificate(cert *x509.Certificate) string
GetEnrollmentIDFromX509Certificate returns the EnrollmentID from the X509 certificate
func GetPrivateKey ¶
func GetPrivateKey(privateKey string) (*rsa.PrivateKey, error)
GetPrivateKey converts a private key []byte to *rsa.PrivateKey object The Private Key has to be PEM encoded
func GetPublicKey ¶
GetPublicKey converts publicKey.pem to *rsa.PublicKey
func GetRSAPrivateKey ¶
func GetRSAPrivateKey(raw []byte) (*rsa.PrivateKey, error)
GetRSAPrivateKey get *rsa.PrivateKey from key pem
func GetX509CertificateFromPEM ¶
func GetX509CertificateFromPEM(cert []byte) (*x509.Certificate, error)
GetX509CertificateFromPEM converts a PEM buffer to an X509 Certificate
func HTTPRequestToString ¶
HTTPRequestToString returns a string for an HTTP request for debuggging
func HTTPResponseToString ¶
HTTPResponseToString returns a string for an HTTP response for debuggging
func MakeFileAbs ¶
MakeFileAbs makes 'file' absolute relative to 'dir' if not already absolute
func NewSelfSignedCert ¶
NewSelfSignedCert returns new key ans cert Takes JSON string as input Returns JSON Strinng with Cert and json Signaure Signature String */
func RSASign ¶
func RSASign(message []byte, shaAlgo string, rsaPrivateKey *rsa.PrivateKey) string
RSASign Signs Message as per RSA Algo returns RSA bigint String Signature ShaAlgo is hard coded right now to SHA384. Will implement dynamic algo**/
func RSASignJSON ¶
func RSASignJSON(jsonString string, signatureJSON string, rsaPrivateKey *rsa.PrivateKey, cert string) string
RSASignJSON Signs JSon string jsonString : JSonString to be signed signatureJson : json string containing signature and ECert certificate : in based64 encoding returns JSON String with updated signature */
func RSAVerifySig ¶
RSAVerifySig Verifies RSA Signature return boolean
func ReadJSONAsMapFile ¶
ReadJSONAsMapFile reads the keyvalue from file system
func ReadJSONAsMapString ¶
ReadJSONAsMapString reads keyvalue from strings
func RemoveQuotes ¶
RemoveQuotes removes outer quotes from a string if necessary
func SignECMessage ¶
SignECMessage generates a certificate and privKey and returns a signedJSON string containing the R and S value.
func StrContained ¶
StrContained returns true if 'str' is in 'strs'; otherwise return false
func ValidateCert ¶
func ValidateCert(cert *x509.Certificate) bool
ValidateCert checks for expiry in the certificate cert Does not check for revocation
func VerifyECMessage ¶
VerifyECMessage Verifies EC Message
func VerifyECMessageImpl ¶
VerifyECMessageImpl implements the Elliptic Curve signature verification
func VerifyMessage ¶
VerifyMessage Gets Public Key from Certificate Certificate can be in PEM or DER Format It verifies both RSA and EC signatures**/
func VerifyRSAMessageImpl ¶
VerifyRSAMessageImpl implements the RSA signature verification
func VerifyToken ¶
func VerifyToken(token string, body []byte) (*x509.Certificate, error)
VerifyToken verifies token signed by either ECDSA or RSA and returns the associated user ID
func WriteJSONAsMapToFile ¶
WriteJSONAsMapToFile reads JSON String from File and Updates it with value
func WriteJSONAsMapToString ¶
WriteJSONAsMapToString writes a json map to a json string
func WriteJSONToString ¶
WriteJSONToString takes a map as input and returns json map
func WriteToJSON ¶
WriteToJSON reads a file name from configfile and writes json file one at a time
Types ¶
type CertificateSpec ¶
type CertificateSpec struct { NotBefore time.Time NotAfter time.Time State string Organization string OrganizationUnit string // contains filtered or unexported fields }
CertificateSpec defines structure for Certificate template certificateType 1: Self Signed , 2 : COP Server Signed , 3 : CSR
func (*CertificateSpec) GetCertificateType ¶
func (spec *CertificateSpec) GetCertificateType() float64
GetCertificateType returns certificateType 1:Self Signed , 2:COP Signed , 3: CSR
func (*CertificateSpec) GetCommonName ¶
func (spec *CertificateSpec) GetCommonName() string
GetCommonName returns the spec's Common Name field/value
func (*CertificateSpec) GetCountry ¶
func (spec *CertificateSpec) GetCountry() string
GetCountry returns the spec's Country field/value
func (*CertificateSpec) GetExtensions ¶
func (spec *CertificateSpec) GetExtensions() *[]pkix.Extension
GetExtensions returns the sepc's extensions
func (*CertificateSpec) GetLocality ¶
func (spec *CertificateSpec) GetLocality() string
GetLocality returs subject's locality
func (*CertificateSpec) GetNotAfter ¶
func (spec *CertificateSpec) GetNotAfter() time.Time
GetNotAfter returns the spec NotAfter (time.Time) field/value
func (*CertificateSpec) GetNotBefore ¶
func (spec *CertificateSpec) GetNotBefore() time.Time
GetNotBefore returns the spec NotBefore (time.Time) field/value
func (*CertificateSpec) GetOrganization ¶
func (spec *CertificateSpec) GetOrganization() string
GetOrganization returns the spec's Organization field/value
func (*CertificateSpec) GetOrganizationalUnit ¶
func (spec *CertificateSpec) GetOrganizationalUnit() string
GetOrganizationalUnit returns subject's OrganizationalUNIT
func (*CertificateSpec) GetPublicKey ¶
func (spec *CertificateSpec) GetPublicKey() interface{}
GetPublicKey returns the spec's Public Key field/value
func (*CertificateSpec) GetSerialNumber ¶
func (spec *CertificateSpec) GetSerialNumber() *big.Int
GetSerialNumber returns the spec's Serial Number field/value
func (*CertificateSpec) GetSignatureAlgorithm ¶
func (spec *CertificateSpec) GetSignatureAlgorithm() x509.SignatureAlgorithm
GetSignatureAlgorithm returns the X509.SignatureAlgorithm field/value
func (*CertificateSpec) GetState ¶
func (spec *CertificateSpec) GetState() string
GetState returns subejct's state
func (*CertificateSpec) GetSubjectKeyID ¶
func (spec *CertificateSpec) GetSubjectKeyID() *[]byte
GetSubjectKeyID returns the spec's subject KeyID
func (*CertificateSpec) GetUsage ¶
func (spec *CertificateSpec) GetUsage() x509.KeyUsage
GetUsage returns the spec's usage (which is the x509.KeyUsage) field/value
type ECDSASignature ¶
ECDSASignature forms the structure for R and S value for ECDSA