예제 #1
0
파일: store.go 프로젝트: Paher/go-cryptoapi
// FindByThumb returns slice of certificates that match given thumbprint. If
// thumbprint supplied could not be decoded from string, FindByThumb will
// return nil slice
func (s *CertStore) FindByThumb(thumb string) []*Cert {
	bThumb, err := hex.DecodeString(thumb)
	if err != nil {
		return nil
	}
	var hashBlob C.CRYPT_HASH_BLOB
	hashBlob.cbData = C.DWORD(len(bThumb))
	hashBlob.pbData = (*C.BYTE)(unsafe.Pointer(&bThumb[0]))
	return s.FindCerts(C.CERT_FIND_HASH, unsafe.Pointer(&hashBlob))
}
예제 #2
0
// FindBySubjectId returns slice of certificates that match given subject key ID. If
// ID supplied could not be decoded from string, FindBySubjectId will
// return nil slice
func (s CertStore) FindBySubjectId(thumb string) []Cert {
	bThumb, err := hex.DecodeString(thumb)
	if err != nil {
		return nil
	}
	var hashBlob C.CRYPT_HASH_BLOB
	hashBlob.cbData = C.DWORD(len(bThumb))
	bThumbPtr := C.CBytes(bThumb)
	defer C.free(bThumbPtr)
	hashBlob.pbData = (*C.BYTE)(bThumbPtr)
	return s.findCerts(C.CERT_FIND_KEY_IDENTIFIER, unsafe.Pointer(&hashBlob))
}
예제 #3
0
파일: store.go 프로젝트: Paher/go-cryptoapi
// GetByThumb returns first certificate in store that match given thumbprint
func (s *CertStore) GetByThumb(thumb string) (*Cert, error) {
	bThumb, err := hex.DecodeString(thumb)
	if err != nil {
		return nil, err
	}
	var hashBlob C.CRYPT_HASH_BLOB
	hashBlob.cbData = C.DWORD(len(bThumb))
	hashBlob.pbData = (*C.BYTE)(unsafe.Pointer(&bThumb[0]))
	if crt := s.GetCert(C.CERT_FIND_HASH, unsafe.Pointer(&hashBlob)); crt == nil {
		return nil, getErr("Error looking up certificate by thumb")
	} else {
		return crt, nil
	}
}
예제 #4
0
// GetBySubjectId returns first certificate in store that match given subject key ID
func (s CertStore) GetBySubjectId(keyId string) (res Cert, err error) {
	bThumb, err := hex.DecodeString(keyId)
	if err != nil {
		return
	}
	var hashBlob C.CRYPT_HASH_BLOB
	hashBlob.cbData = C.DWORD(len(bThumb))
	bThumbPtr := C.CBytes(bThumb)
	defer C.free(bThumbPtr)
	hashBlob.pbData = (*C.BYTE)(bThumbPtr)
	if res.pCert = s.getCert(C.CERT_FIND_KEY_IDENTIFIER, unsafe.Pointer(&hashBlob)); res.pCert == nil {
		err = getErr("Error looking up certificate by subject key id")
		return
	}
	return
}