コード例 #1
0
func (reg Registration) Export(password string) (*RegistrationExport, error) {
	keyBlock, err := reg.SigningKey.EncryptPrivateKey(password, utils.PemDefaultCipher)
	if nil != err {
		return nil, err
	}
	jsonBytes, err := json.Marshal(rawRegistrationExportJson{
		Resource:           reg.Resource,
		LinkTermsOfService: reg.LinkTermsOfService,
		RecoveryToken:      reg.RecoveryToken,
	})
	if nil != err {
		return nil, err
	}
	jsonBlock := &pem.Block{
		Type:  pemTypeAcmeJsonRegistration,
		Bytes: jsonBytes,
	}
	if err := utils.EncryptPemBlock(jsonBlock, password, utils.PemDefaultCipher); nil != err {
		return nil, err
	}
	return &RegistrationExport{
		JsonPem:       pem.EncodeToMemory(jsonBlock),
		SigningKeyPem: pem.EncodeToMemory(keyBlock),
		Location:      reg.Location,
		Name:          reg.Name,
	}, nil
}
コード例 #2
0
func (auth Authorization) Export(password string) (*AuthorizationExport, error) {
	if jsonBytes, err := json.Marshal(auth); nil != err {
		return nil, err
	} else {
		jsonBlock := &pem.Block{
			Type:  pemTypeAcmeJsonAuthorization,
			Bytes: jsonBytes,
		}
		if err := utils.EncryptPemBlock(jsonBlock, password, utils.PemDefaultCipher); nil != err {
			return nil, err
		}
		return &AuthorizationExport{
			JsonPem: pem.EncodeToMemory(jsonBlock),
		}, nil
	}
}
コード例 #3
0
func (cert Certificate) Export(password string) (*CertificateExport, error) {
	var privateKeyBlob []byte
	if nil != cert.PrivateKey {
		privateKeyBlock := *cert.PrivateKey
		if err := utils.EncryptPemBlock(&privateKeyBlock, password, utils.PemDefaultCipher); nil != err {
			return nil, err
		}
		privateKeyBlob = pem.EncodeToMemory(&privateKeyBlock)
	}

	return &CertificateExport{
		CertificatePem: pem.EncodeToMemory(cert.Certificate),
		PrivateKeyPem:  privateKeyBlob,
		Location:       cert.Location,
		LinkIssuer:     cert.LinkIssuer,
	}, nil
}