utils

package
v0.0.0-...-c03dbfc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2020 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Env : Env variable to hold Env default Variable values

View Source
var MongoDb string

MongoDb : Holds Mongo Db Name

View Source
var PhCertExtensionIDs = &models.PhCertExtensions{
	AIKName:       asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 54621, 100, 0},
	OwnerPrnOID:   asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 54621, 100, 1},
	OwnernameSig:  asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 54621, 100, 2},
	TokenID:       asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 54621, 100, 3},
	CertifyAttest: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 54621, 100, 4},
	CertifySig:    asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 54621, 100, 5},
	QuoteAttest:   asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 54621, 100, 6},
	QuoteSig:      asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 54621, 100, 7},
	QuotePcrList:  asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 54621, 100, 8},
	DevicePRN:     asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 54621, 100, 9},
}

PhCertExtensionIDs all the indentifiers for pantahub extensions on a certificate values

Functions

func CreateTmpFile

func CreateTmpFile(content []byte, name string, dir string) (string, error)

CreateTmpFile create a temporal file with a content, return and string with the path

func ErrorMessageJSON

func ErrorMessageJSON(err error, code string) string

ErrorMessageJSON return a rest error with the message

func ErrorResponse

func ErrorResponse(resp *restful.Response, err error, status int, code string)

ErrorResponse get the server response and generate a proper json response

func FromBase64DerToExtension

func FromBase64DerToExtension(base64Cert, format string) ([]byte, error)

FromBase64DerToExtension get a certificate with base64 encode and formated

func GetCertifiedName

func GetCertifiedName(exts *PHExtensions, public tpm2.Public) (name *tpm2.Name, qname *tpm2.Name, err error)

GetCertifiedName get and validate certificate name agains TPMB_PUBLIC part

func GetEnv

func GetEnv(key, defaultValue string) string

GetEnv return values of the environment

func GetMongoClient

func GetMongoClient() (*mongo.Client, error)

GetMongoClient : To Get Mongo Client Object

func GetMongoClientTest

func GetMongoClientTest() (*mongo.Client, error)

GetMongoClientTest : To Get Mongo Client Object

func GetMongoSession

func GetMongoSession() (*mgo.Session, error)

GetMongoSession return mongo session

func GetTrustedRoots

func GetTrustedRoots() (*x509.CertPool, error)

GetTrustedRoots return and pool of trusted root credentials for TPM

func GetTrustedRootsFromBundle

func GetTrustedRootsFromBundle() (*x509.CertPool, error)

GetTrustedRootsFromBundle return and pool of trusted root credentials for TPM

func IDGetPrn

func IDGetPrn(id bson.ObjectId, serviceName string) string

IDGetPrn get prn from ID

func ParseHeaderPhClientCertificate

func ParseHeaderPhClientCertificate(header string) (*x509.Certificate, error)

ParseHeaderPhClientCertificate get a URL encode pem certificate

func ParsePEMBase64EncodeCert

func ParsePEMBase64EncodeCert(encodeCert string) (*x509.Certificate, error)

ParsePEMBase64EncodeCert parse a hex encoded certificate

func ParsePEMCertString

func ParsePEMCertString(pemCert []byte) (*x509.Certificate, error)

ParsePEMCertString parse a pem certificate

func ParsePEMHexEncodeCert

func ParsePEMHexEncodeCert(encodeCert string) (*x509.Certificate, error)

ParsePEMHexEncodeCert parse a hex encoded certificate

func ParsePrivateKey

func ParsePrivateKey(der []byte) (crypto.PrivateKey, error)

ParsePrivateKey parse private key from DER content

func ParsePublicKey

func ParsePublicKey(der []byte) (crypto.PublicKey, error)

ParsePublicKey parse public key from DER content

func PrnGetID

func PrnGetID(prn string) string

PrnGetID make this a nice prn helper tool

func RemoveIndex

func RemoveIndex(a []interface{}, i int) []interface{}

RemoveIndex remove and index from and array

func SetupEnvDefaults

func SetupEnvDefaults()

SetupEnvDefaults : Initialize EnvDefaults

func Tpm2NameToString

func Tpm2NameToString(name tpm2.Name) string

Tpm2NameToString convert tpm2.Name to string

func Tpm2PublicName

func Tpm2PublicName(pub tpm2.Public) (string, error)

Tpm2PublicName get tpm name as string

func ValidateAcaSigned

func ValidateAcaSigned(cert *x509.Certificate) error

ValidateAcaSigned validate a certificate that has been signed by pantahub ACA

func ValidateAttestationSignature

func ValidateAttestationSignature(attestation, signature []byte, akPub *rsa.PublicKey) error

ValidateAttestationSignature validate certification signature

func ValidateCASigned

func ValidateCASigned(cert *x509.Certificate) error

ValidateCASigned validate a certificate that has been signed by pantahub CA

func ValidateCertificateSelfSigned

func ValidateCertificateSelfSigned(cert *x509.Certificate) error

ValidateCertificateSelfSigned validate that a certificate is self signed

func ValidateTPMPublicKey

func ValidateTPMPublicKey(pubKey *rsa.PublicKey, pubPart tpm2.Public) error

ValidateTPMPublicKey validate a tpm public key

Types

type Crypter

type Crypter struct {
	// contains filtered or unexported fields
}

Crypter create Crypter

func NewCrypter

func NewCrypter(key []byte, iv []byte) (*Crypter, error)

NewCrypter define new crypter

func (*Crypter) Decrypt

func (c *Crypter) Decrypt(cipherText []byte) ([]byte, error)

Decrypt decrypt

func (*Crypter) Encrypt

func (c *Crypter) Encrypt(plainText []byte) ([]byte, error)

Encrypt Encrypt

type PHExtensions

type PHExtensions struct {
	CertifyAttest    *tpm2.AttestationData
	CertifySignature *tpm2.Signature
	QuoteAttest      *tpm2.AttestationData
	QuoteSignature   *tpm2.Signature
	QuotePcrList     []byte
	OwnerTokenID     []byte
	Owner            string
	NameSigByOwner   []byte
	Raw              *rawExtensions
}

PHExtensions pantacor certificate extensions

func ProcessPHExtensionsCsr

func ProcessPHExtensionsCsr(cert *x509.CertificateRequest) (*PHExtensions, error)

ProcessPHExtensionsCsr process all pantacor extensions if they exists

func ProcessPHExtentions

func ProcessPHExtentions(cert *x509.Certificate) (*PHExtensions, error)

ProcessPHExtentions process all pantacor extensions if they exists

type Prn

type Prn string

Prn type of elements

func (*Prn) GetInfo

func (p *Prn) GetInfo() (*PrnInfo, error)

GetInfo get information from PRN

type PrnInfo

type PrnInfo struct {
	Domain   string
	Service  string
	Resource string
}

PrnInfo full prninfo

func (*PrnInfo) Equals

func (p *PrnInfo) Equals(c *PrnInfo) bool

Equals compare two prn

type PrnParseError

type PrnParseError string

PrnParseError error

func (PrnParseError) Error

func (s PrnParseError) Error() string

Error get parse error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL