5
5
// Generate a self-signed X.509 certificate for a TLS server. Outputs to
6
6
// 'cert.pem' and 'key.pem' and will overwrite existing files.
7
7
8
- package main
8
+ package certificates
9
9
10
10
import (
11
11
"crypto/ecdsa"
@@ -134,10 +134,10 @@ func generateSingleCertificate(isCa bool) (*x509.Certificate, error) {
134
134
return & template , nil
135
135
}
136
136
137
- // migrateCertificatesGeneratedWithOldAgentVersions checks if certificates generated
137
+ // MigrateCertificatesGeneratedWithOldAgentVersions checks if certificates generated
138
138
// with an old version of the Agent needs to be migrated to the current certificates
139
139
// directory, and performs the migration if needed.
140
- func migrateCertificatesGeneratedWithOldAgentVersions (certsDir * paths.Path ) {
140
+ func MigrateCertificatesGeneratedWithOldAgentVersions (certsDir * paths.Path ) {
141
141
if certsDir .Join ("ca.cert.pem" ).Exist () {
142
142
// The new certificates are already set-up, nothing to do
143
143
return
@@ -161,7 +161,8 @@ func migrateCertificatesGeneratedWithOldAgentVersions(certsDir *paths.Path) {
161
161
}
162
162
}
163
163
164
- func generateCertificates (certsDir * paths.Path ) {
164
+ // GenerateCertificates will generate the required certificates useful for a HTTPS connection on localhost
165
+ func GenerateCertificates (certsDir * paths.Path ) {
165
166
certsDir .Join ("ca.cert.pem" ).Remove ()
166
167
certsDir .Join ("ca.key.pem" ).Remove ()
167
168
certsDir .Join ("cert.pem" ).Remove ()
@@ -260,7 +261,8 @@ func generateCertificates(certsDir *paths.Path) {
260
261
}
261
262
}
262
263
263
- func certHandler (c * gin.Context ) {
264
+ // CertHandler will expone the certificate (we do not know why this was required)
265
+ func CertHandler (c * gin.Context ) {
264
266
if strings .Contains (c .Request .UserAgent (), "Firefox" ) {
265
267
c .Header ("content-type" , "application/x-x509-ca-cert" )
266
268
c .File ("ca.cert.cer" )
@@ -271,7 +273,8 @@ func certHandler(c *gin.Context) {
271
273
})
272
274
}
273
275
274
- func deleteCertHandler (c * gin.Context ) {
276
+ // DeleteCertHandler will delete the certificates
277
+ func DeleteCertHandler (c * gin.Context ) {
275
278
DeleteCertificates (config .GetCertificatesDir ())
276
279
}
277
280
0 commit comments