Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
Kirill Smelkov
go
Commits
99d258a2
Commit
99d258a2
authored
Apr 05, 2010
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crypto/tls: good defaults
R=agl1 CC=golang-dev
https://golang.org/cl/851041
parent
6c196015
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
1 deletion
+61
-1
src/pkg/crypto/tls/common.go
src/pkg/crypto/tls/common.go
+39
-0
src/pkg/crypto/tls/tls.go
src/pkg/crypto/tls/tls.go
+22
-1
No files found.
src/pkg/crypto/tls/common.go
View file @
99d258a2
...
...
@@ -5,9 +5,13 @@
package
tls
import
(
"crypto/rand"
"crypto/rsa"
"io"
"io/ioutil"
"once"
"os"
"time"
)
const
(
...
...
@@ -130,3 +134,38 @@ func (nop) Sum() []byte { return nil }
func
(
nop
)
Reset
()
{}
func
(
nop
)
Size
()
int
{
return
0
}
// The defaultConfig is used in place of a nil *Config in the TLS server and client.
var
varDefaultConfig
*
Config
func
defaultConfig
()
*
Config
{
once
.
Do
(
initDefaultConfig
)
return
varDefaultConfig
}
// Possible certificate files; stop after finding one.
// On OS X we should really be using the Directory Services keychain
// but that requires a lot of Mach goo to get at. Instead we use
// the same root set that curl uses.
var
certFiles
=
[]
string
{
"/etc/ssl/certs/ca-certificates.crt"
,
// Linux etc
"/usr/share/curl/curl-ca-bundle.crt"
,
// OS X
}
func
initDefaultConfig
()
{
roots
:=
NewCASet
()
for
_
,
file
:=
range
certFiles
{
data
,
err
:=
ioutil
.
ReadFile
(
file
)
if
err
==
nil
{
roots
.
SetFromPEM
(
data
)
break
}
}
varDefaultConfig
=
&
Config
{
Rand
:
rand
.
Reader
,
Time
:
time
.
Seconds
,
RootCAs
:
roots
,
}
}
src/pkg/crypto/tls/tls.go
View file @
99d258a2
...
...
@@ -125,6 +125,9 @@ type handshaker interface {
// Server establishes a secure connection over the given connection and acts
// as a TLS server.
func
startTLSGoroutines
(
conn
net
.
Conn
,
h
handshaker
,
config
*
Config
)
*
Conn
{
if
config
==
nil
{
config
=
defaultConfig
()
}
tls
:=
new
(
Conn
)
tls
.
Conn
=
conn
...
...
@@ -167,7 +170,6 @@ func (l *Listener) Accept() (c net.Conn, err os.Error) {
if
err
!=
nil
{
return
}
c
=
Server
(
c
,
l
.
config
)
return
}
...
...
@@ -179,8 +181,27 @@ func (l *Listener) Addr() net.Addr { return l.listener.Addr() }
// NewListener creates a Listener which accepts connections from an inner
// Listener and wraps each connection with Server.
func
NewListener
(
listener
net
.
Listener
,
config
*
Config
)
(
l
*
Listener
)
{
if
config
==
nil
{
config
=
defaultConfig
()
}
l
=
new
(
Listener
)
l
.
listener
=
listener
l
.
config
=
config
return
}
func
Listen
(
network
,
laddr
string
)
(
net
.
Listener
,
os
.
Error
)
{
l
,
err
:=
net
.
Listen
(
network
,
laddr
)
if
err
!=
nil
{
return
nil
,
err
}
return
NewListener
(
l
,
nil
),
nil
}
func
Dial
(
network
,
laddr
,
raddr
string
)
(
net
.
Conn
,
os
.
Error
)
{
c
,
err
:=
net
.
Dial
(
network
,
laddr
,
raddr
)
if
err
!=
nil
{
return
nil
,
err
}
return
Client
(
c
,
nil
),
nil
}
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