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
3faac668
Commit
3faac668
authored
6 years ago
by
Mariano Cano
Browse files
Options
Downloads
Patches
Plain Diff
Add initial support for java.
parent
ad5f4a56
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
truststore.go
+9
-3
9 additions, 3 deletions
truststore.go
truststore_java.go
+29
-18
29 additions, 18 deletions
truststore_java.go
with
38 additions
and
21 deletions
truststore.go
+
9
−
3
View file @
3faac668
...
@@ -58,8 +58,12 @@ func InstallFile(filename string, opts ...Option) error {
...
@@ -58,8 +58,12 @@ func InstallFile(filename string, opts ...Option) error {
func
installCertificate
(
filename
string
,
cert
*
x509
.
Certificate
,
opts
[]
Option
)
error
{
func
installCertificate
(
filename
string
,
cert
*
x509
.
Certificate
,
opts
[]
Option
)
error
{
o
:=
newOptions
(
opts
)
o
:=
newOptions
(
opts
)
if
o
.
withJava
{
if
o
.
withJava
&&
hasJava
{
if
!
checkJava
(
cert
)
{
if
err
:=
installJava
(
filename
,
cert
);
err
!=
nil
{
return
err
}
}
}
}
if
o
.
withFirefox
&&
hasNSS
()
{
if
o
.
withFirefox
&&
hasNSS
()
{
if
!
checkNSS
(
cert
)
{
if
!
checkNSS
(
cert
)
{
...
@@ -99,7 +103,9 @@ func UninstallFile(filename string, opts ...Option) error {
...
@@ -99,7 +103,9 @@ func UninstallFile(filename string, opts ...Option) error {
func
uninstallCertificate
(
filename
string
,
cert
*
x509
.
Certificate
,
opts
[]
Option
)
error
{
func
uninstallCertificate
(
filename
string
,
cert
*
x509
.
Certificate
,
opts
[]
Option
)
error
{
o
:=
newOptions
(
opts
)
o
:=
newOptions
(
opts
)
if
o
.
withJava
{
if
o
.
withJava
{
if
err
:=
uninstallJava
(
filename
,
cert
);
err
!=
nil
{
return
err
}
}
}
if
o
.
withFirefox
&&
checkNSS
(
cert
)
{
if
o
.
withFirefox
&&
checkNSS
(
cert
)
{
if
err
:=
uninstallNSS
(
filename
,
cert
);
err
!=
nil
{
if
err
:=
uninstallNSS
(
filename
,
cert
);
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
truststore_java.go
+
29
−
18
View file @
3faac668
// +build ignore
// Copyright (c) 2018 The truststore Authors. All rights reserved.
// Copyright 2018 The Go Authors. All rights reserved.
// Copyright (c) 2018 The mkcert Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
truststore
package
truststore
...
@@ -55,10 +53,12 @@ func init() {
...
@@ -55,10 +53,12 @@ func init() {
if
err
==
nil
{
if
err
==
nil
{
cacertsPath
=
filepath
.
Join
(
v
,
"jre"
,
"lib"
,
"security"
,
"cacerts"
)
cacertsPath
=
filepath
.
Join
(
v
,
"jre"
,
"lib"
,
"security"
,
"cacerts"
)
}
}
println
(
cacertsPath
)
}
}
}
}
func
(
m
*
mkcert
)
checkJava
(
)
bool
{
func
checkJava
(
cert
*
x509
.
Certificate
)
bool
{
if
!
hasKeytool
{
if
!
hasKeytool
{
return
false
return
false
}
}
...
@@ -72,46 +72,57 @@ func (m *mkcert) checkJava() bool {
...
@@ -72,46 +72,57 @@ func (m *mkcert) checkJava() bool {
}
}
keytoolOutput
,
err
:=
exec
.
Command
(
keytoolPath
,
"-list"
,
"-keystore"
,
cacertsPath
,
"-storepass"
,
storePass
)
.
CombinedOutput
()
keytoolOutput
,
err
:=
exec
.
Command
(
keytoolPath
,
"-list"
,
"-keystore"
,
cacertsPath
,
"-storepass"
,
storePass
)
.
CombinedOutput
()
fatalIfCmdErr
(
err
,
"keytool -list"
,
keytoolOutput
)
if
err
!=
nil
{
debug
(
"failed to execute
\"
keytool -list
\"
: %s
\n\n
%s"
,
err
,
keytoolOutput
)
return
false
}
// keytool outputs SHA1 and SHA256 (Java 9+) certificates in uppercase hex
// keytool outputs SHA1 and SHA256 (Java 9+) certificates in uppercase hex
// with each octet pair delimitated by ":". Drop them from the keytool output
// with each octet pair delimitated by ":". Drop them from the keytool output
keytoolOutput
=
bytes
.
Replace
(
keytoolOutput
,
[]
byte
(
":"
),
nil
,
-
1
)
keytoolOutput
=
bytes
.
Replace
(
keytoolOutput
,
[]
byte
(
":"
),
nil
,
-
1
)
// pre-Java 9 uses SHA1 fingerprints
// pre-Java 9 uses SHA1 fingerprints
s1
,
s256
:=
sha1
.
New
(),
sha256
.
New
()
s1
,
s256
:=
sha1
.
New
(),
sha256
.
New
()
return
exists
(
m
.
caC
ert
,
s1
,
keytoolOutput
)
||
exists
(
m
.
caC
ert
,
s256
,
keytoolOutput
)
return
exists
(
c
ert
,
s1
,
keytoolOutput
)
||
exists
(
c
ert
,
s256
,
keytoolOutput
)
}
}
func
(
m
*
mkcert
)
installJava
()
{
func
installJava
(
filename
string
,
cert
*
x509
.
Certificate
)
error
{
args
:=
[]
string
{
args
:=
[]
string
{
"-importcert"
,
"-noprompt"
,
"-importcert"
,
"-noprompt"
,
"-keystore"
,
cacertsPath
,
"-keystore"
,
cacertsPath
,
"-storepass"
,
storePass
,
"-storepass"
,
storePass
,
"-file"
,
file
path
.
Join
(
m
.
CAROOT
,
rootN
ame
)
,
"-file"
,
file
n
ame
,
"-alias"
,
m
.
caU
niqueName
(),
"-alias"
,
u
niqueName
(
cert
),
}
}
out
,
err
:=
m
.
execKeytool
(
exec
.
Command
(
keytoolPath
,
args
...
))
out
,
err
:=
execKeytool
(
exec
.
Command
(
keytoolPath
,
args
...
))
fatalIfCmdErr
(
err
,
"keytool -importcert"
,
out
)
if
err
!=
nil
{
return
cmdError
(
err
,
"keytool -importcert"
,
out
)
}
return
nil
}
}
func
(
m
*
mkcert
)
uninstallJava
(
)
{
func
uninstallJava
(
filename
string
,
cert
*
x509
.
Certificate
)
error
{
args
:=
[]
string
{
args
:=
[]
string
{
"-delete"
,
"-delete"
,
"-alias"
,
m
.
caU
niqueName
(),
"-alias"
,
u
niqueName
(
cert
),
"-keystore"
,
cacertsPath
,
"-keystore"
,
cacertsPath
,
"-storepass"
,
storePass
,
"-storepass"
,
storePass
,
}
}
out
,
err
:=
m
.
execKeytool
(
exec
.
Command
(
keytoolPath
,
args
...
))
out
,
err
:=
execKeytool
(
exec
.
Command
(
keytoolPath
,
args
...
))
if
bytes
.
Contains
(
out
,
[]
byte
(
"does not exist"
))
{
if
bytes
.
Contains
(
out
,
[]
byte
(
"does not exist"
))
{
return
// cert didn't exist
return
nil
}
if
err
!=
nil
{
cmdError
(
err
,
"keytool -delete"
,
out
)
}
}
fatalIfCmdErr
(
err
,
"keytool -delete"
,
out
)
return
nil
}
}
// execKeytool will execute a "keytool" command and if needed re-execute
// execKeytool will execute a "keytool" command and if needed re-execute
// the command wrapped in 'sudo' to work around file permissions.
// the command wrapped in 'sudo' to work around file permissions.
func
(
m
*
mkcert
)
execKeytool
(
cmd
*
exec
.
Cmd
)
([]
byte
,
error
)
{
func
execKeytool
(
cmd
*
exec
.
Cmd
)
([]
byte
,
error
)
{
out
,
err
:=
cmd
.
CombinedOutput
()
out
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
&&
bytes
.
Contains
(
out
,
[]
byte
(
"java.io.FileNotFoundException"
))
&&
runtime
.
GOOS
!=
"windows"
{
if
err
!=
nil
&&
bytes
.
Contains
(
out
,
[]
byte
(
"java.io.FileNotFoundException"
))
&&
runtime
.
GOOS
!=
"windows"
{
origArgs
:=
cmd
.
Args
[
1
:
]
origArgs
:=
cmd
.
Args
[
1
:
]
...
...
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