Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Truststore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
smallstep
Truststore
Commits
cf7dc648
Commit
cf7dc648
authored
3 years ago
by
qiu-x
Browse files
Options
Downloads
Patches
Plain Diff
Add FreeBSD `certctl` support
parent
23dd8829
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
truststore_freebsd.go
+103
-0
103 additions, 0 deletions
truststore_freebsd.go
with
103 additions
and
0 deletions
truststore_freebsd.go
0 → 100644
+
103
−
0
View file @
cf7dc648
package
truststore
import
(
"bytes"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
)
var
(
// NSSProfile is the path of the Firefox profiles.
NSSProfile
=
os
.
Getenv
(
"HOME"
)
+
"/.mozilla/firefox/*"
// CertutilInstallHelp is the command to add NSS support.
CertutilInstallHelp
=
""
// SystemTrustFilename is the format used to name the root certificates.
SystemTrustFilename
string
// SystemTrustCommand is the command used to update the system truststore.
SystemTrustCommand
[]
string
)
func
init
()
{
if
!
pathExists
(
"/usr/local/etc/ssl/certs"
)
{
err
:=
os
.
Mkdir
(
"/usr/local/etc/ssl/certs"
,
0755
)
if
err
!=
nil
{
SystemTrustCommand
=
nil
log
.
Fatal
(
err
)
return
}
}
SystemTrustCommand
=
[]
string
{
"certctl"
,
"rehash"
}
SystemTrustFilename
=
"/usr/local/etc/ssl/certs/%s.crt"
}
func
pathExists
(
path
string
)
bool
{
_
,
err
:=
os
.
Stat
(
path
)
return
err
==
nil
}
func
systemTrustFilename
(
cert
*
x509
.
Certificate
)
string
{
return
fmt
.
Sprintf
(
SystemTrustFilename
,
strings
.
Replace
(
uniqueName
(
cert
),
" "
,
"_"
,
-
1
))
}
func
installPlatform
(
filename
string
,
cert
*
x509
.
Certificate
)
error
{
if
SystemTrustCommand
==
nil
{
return
ErrNotSupported
}
data
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
return
err
}
cmd
:=
CommandWithSudo
(
"tee"
,
systemTrustFilename
(
cert
))
cmd
.
Stdin
=
bytes
.
NewReader
(
data
)
out
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
return
NewCmdError
(
err
,
cmd
,
out
)
}
cmd
=
CommandWithSudo
(
SystemTrustCommand
...
)
out
,
err
=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
return
NewCmdError
(
err
,
cmd
,
out
)
}
debug
(
"certificate installed properly in FreeBSD trusts"
)
return
nil
}
func
uninstallPlatform
(
filename
string
,
cert
*
x509
.
Certificate
)
error
{
if
SystemTrustCommand
==
nil
{
return
ErrNotSupported
}
cmd
:=
CommandWithSudo
(
"rm"
,
"-f"
,
systemTrustFilename
(
cert
))
out
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
return
NewCmdError
(
err
,
cmd
,
out
)
}
cmd
=
CommandWithSudo
(
SystemTrustCommand
...
)
out
,
err
=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
return
NewCmdError
(
err
,
cmd
,
out
)
}
debug
(
"certificate uninstalled properly from FreeBSD trusts"
)
return
nil
}
func
CommandWithSudo
(
cmd
...
string
)
*
exec
.
Cmd
{
if
_
,
err
:=
exec
.
LookPath
(
"sudo"
);
err
!=
nil
{
return
exec
.
Command
(
cmd
[
0
],
cmd
[
1
:
]
...
)
}
return
exec
.
Command
(
"sudo"
,
append
([]
string
{
"--"
},
cmd
...
)
...
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment