Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Łukasz Nowak
caddy
Commits
79de2a5d
Commit
79de2a5d
authored
Sep 26, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stubbed out basic code to obtain Let's Encrypt cert
parent
ca1f1362
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
config/config.go
config/config.go
+54
-0
No files found.
config/config.go
View file @
79de2a5d
package
config
package
config
import
(
import
(
"crypto/rand"
"crypto/rsa"
"errors"
"fmt"
"fmt"
"io"
"io"
"log"
"log"
...
@@ -11,6 +14,7 @@ import (
...
@@ -11,6 +14,7 @@ import (
"github.com/mholt/caddy/config/setup"
"github.com/mholt/caddy/config/setup"
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/server"
"github.com/mholt/caddy/server"
"github.com/xenolf/lego/acme"
)
)
const
(
const
(
...
@@ -73,10 +77,60 @@ func Load(filename string, input io.Reader) (Group, error) {
...
@@ -73,10 +77,60 @@ func Load(filename string, input io.Reader) (Group, error) {
// restore logging settings
// restore logging settings
log
.
SetFlags
(
flags
)
log
.
SetFlags
(
flags
)
privateKey
,
err
:=
rsa
.
GenerateKey
(
rand
.
Reader
,
2048
)
if
err
!=
nil
{
return
Group
{},
errors
.
New
(
"Error Generating Key:"
+
err
.
Error
())
}
for
_
,
cfg
:=
range
configs
{
// TODO: && hostname does not resolve to localhost (?) && TLS is not force-disabled
if
!
cfg
.
TLS
.
Enabled
{
// Initiate Let's Encrypt
user
:=
LetsEncryptUser
{
Email
:
"example@mail.com"
,
Key
:
privateKey
,
}
client
:=
acme
.
NewClient
(
"http://192.168.99.100:4000"
,
&
user
,
2048
,
"5001"
)
reg
,
err
:=
client
.
Register
()
if
err
!=
nil
{
return
Group
{},
errors
.
New
(
"Error Registering: "
+
err
.
Error
())
}
user
.
Registration
=
reg
err
=
client
.
AgreeToTos
()
if
err
!=
nil
{
return
Group
{},
errors
.
New
(
"Error Agreeing to ToS: "
+
err
.
Error
())
}
certs
,
err
:=
client
.
ObtainCertificates
([]
string
{
"caddy.dev"
})
if
err
!=
nil
{
return
Group
{},
errors
.
New
(
"Error Obtaining Certs: "
+
err
.
Error
())
}
fmt
.
Printf
(
"%#v
\n
"
,
certs
)
}
}
// Group by address/virtualhosts
// Group by address/virtualhosts
return
arrangeBindings
(
configs
)
return
arrangeBindings
(
configs
)
}
}
type
LetsEncryptUser
struct
{
Email
string
Registration
*
acme
.
RegistrationResource
Key
*
rsa
.
PrivateKey
}
func
(
u
LetsEncryptUser
)
GetEmail
()
string
{
return
u
.
Email
}
func
(
u
LetsEncryptUser
)
GetRegistration
()
*
acme
.
RegistrationResource
{
return
u
.
Registration
}
func
(
u
LetsEncryptUser
)
GetPrivateKey
()
*
rsa
.
PrivateKey
{
return
u
.
Key
}
// serverBlockToConfig makes a config for the server block
// serverBlockToConfig makes a config for the server block
// by executing the tokens that were parsed. The returned
// by executing the tokens that were parsed. The returned
// config is shared among all hosts/addresses for the server
// config is shared among all hosts/addresses for the server
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment