Ejemplo n.º 1
0
func (storage *sqlStorage) saveCertificate(id int64, registration_id int64, cert types.Certificate) error {
	export, err := cert.Export(storage.lastPassword())
	if nil != err {
		return err
	}

	_, err = storage.db.Exec(
		`UPDATE certificate SET
			registration_id = $1, location = $2, linkIssuer = $3, certificatePem = $4, privateKeyPem = $5
		WHERE id = $6`,
		registration_id, cert.Location, cert.LinkIssuer,
		export.CertificatePem, export.PrivateKeyPem, id)

	return err
}
Ejemplo n.º 2
0
func (sreg *sqlStorageRegistration) NewCertificate(cert types.Certificate) (i.StorageCertificate, error) {
	export, err := cert.Export(sreg.storage.lastPassword())
	if nil != err {
		return nil, err
	}

	_, err = sreg.storage.db.Exec(
		`INSERT INTO certificate (registration_id, location, linkIssuer, certificatePem, privateKeyPem) VALUES
			($1, $2, $3, $4, $5)`,
		sreg.id, cert.Location, cert.LinkIssuer,
		export.CertificatePem, export.PrivateKeyPem)
	if nil != err {
		return nil, err
	}

	return sreg.LoadCertificate(cert.Location)
}