Skip to content

Commit 32acf64

Browse files
committed
some
2 parents e1c6fdb + 32d7938 commit 32acf64

17 files changed

+463
-215
lines changed

CHANGELOG.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- Comprehensive samples directory with organized examples
12+
- Certificate generation scripts for GOST, SM2, and standard algorithms
13+
- Protocol configuration examples for VMess and VLESS
14+
- Server startup scripts for different certificate types
15+
- Detailed README.md with usage examples and troubleshooting
16+
17+
### Changed
18+
- Simplified samples directory structure to single level
19+
- Consolidated all files into main samples directory
20+
- Removed excessive subdirectories and redundant README files
21+
- Streamlined documentation with single comprehensive README.md
22+
23+
### Removed
24+
- Complex nested directory structure
25+
- Multiple redundant README files
26+
- Empty subdirectories
27+
- Over-engineered organization
28+
29+
## File Structure
30+
31+
### Simplified Organization
32+
```
33+
samples/
34+
├── README.md # Comprehensive documentation
35+
├── make_cert_*.sh # Certificate generation scripts
36+
├── vmess_*.json # VMess protocol configurations
37+
├── vless_*.json # VLESS protocol configurations
38+
└── run_*.sh # Server startup scripts
39+
```
40+
41+
### Features
42+
- **Certificate Generation**: Scripts for SM2, GOST2012_256, and GOST2012_512 certificates
43+
- **Protocol Examples**: Complete VMess and VLESS configurations with various certificate types
44+
- **Server Scripts**: Ready-to-use startup scripts for different configurations
45+
- **Documentation**: Single comprehensive README with examples and troubleshooting
46+
47+
### Security Improvements
48+
- Proper file permissions for certificate scripts
49+
- Secure certificate generation practices
50+
- Best practices documentation for production use
51+
- Clear security warnings and guidelines

common/crypto/gost/gost_x509.go

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@ import (
1212
"github.com/pedroalbanese/gogost/gost3410"
1313
)
1414

15-
// GOST signature algorithm constants
16-
const (
17-
GOST256 = 0x0601 // GOST R 34.10-2012 256-bit
18-
GOST512 = 0x0602 // GOST R 34.10-2012 512-bit
19-
)
20-
2115
// GenerateGOSTSelfSignedCert создает самоподписанный X.509 сертификат GOST2012 (256 или 512)
22-
func GenerateGOSTSelfSignedCert(curve *gost3410.Curve, sigAlg x509.SignatureAlgorithm, cn string, expireDays int) ([]byte, []byte, error) {
16+
func GenerateGOSTSelfSignedCert(curve *gost3410.Curve, cn string, expireDays int) ([]byte, []byte, error) {
2317
fmt.Printf("DEBUG: Starting GenerateGOSTSelfSignedCert\n")
2418

2519
prvRaw := make([]byte, curve.PointSize())
@@ -43,34 +37,26 @@ func GenerateGOSTSelfSignedCert(curve *gost3410.Curve, sigAlg x509.SignatureAlgo
4337
notAfter := notBefore.Add(time.Duration(expireDays) * 24 * time.Hour)
4438
serial := big.NewInt(time.Now().UnixNano())
4539

46-
// Create certificate template with proper GOST structure
40+
// Determine the correct signature algorithm based on curve size
41+
var signatureAlgorithm x509.SignatureAlgorithm
42+
if curve.PointSize() == 32 {
43+
signatureAlgorithm = x509.GOST256
44+
} else {
45+
signatureAlgorithm = x509.GOST512
46+
}
47+
4748
template := x509.Certificate{
4849
SerialNumber: serial,
4950
NotBefore: notBefore,
5051
NotAfter: notAfter,
51-
SignatureAlgorithm: sigAlg,
52-
Subject: pkix.Name{
53-
Country: []string{"RU"},
54-
Province: []string{"Krasnoyarsk"},
55-
Locality: []string{"Krasnoyarsk"},
56-
Organization: []string{"Dolboyob Research"},
57-
OrganizationalUnit: []string{"testing"},
58-
CommonName: cn,
59-
},
60-
Issuer: pkix.Name{
61-
Country: []string{"RU"},
62-
Province: []string{"Krasnoyarsk"},
63-
Locality: []string{"Krasnoyarsk"},
64-
Organization: []string{"Dolboyob Research"},
65-
OrganizationalUnit: []string{"testing"},
66-
CommonName: cn,
67-
},
52+
SignatureAlgorithm: signatureAlgorithm,
53+
Subject: pkix.Name{CommonName: cn},
6854
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
6955
BasicConstraintsValid: true,
7056
IsCA: false,
7157
}
7258

73-
fmt.Printf("DEBUG: About to call CreateCertificate\n")
59+
fmt.Printf("DEBUG: About to call CreateCertificate with signature algorithm: %d\n", signatureAlgorithm)
7460
certDER, err := x509.CreateCertificate(
7561
rand.Reader,
7662
&template, &template, pub,
@@ -111,11 +97,20 @@ func GenerateGOSTCAChildCert(curve *gost3410.Curve, sigAlg x509.SignatureAlgorit
11197
notBefore := time.Now()
11298
notAfter := notBefore.Add(time.Duration(expireDays) * 24 * time.Hour)
11399
serial := big.NewInt(time.Now().UnixNano())
100+
101+
// Determine the correct signature algorithm based on curve size
102+
var signatureAlgorithm x509.SignatureAlgorithm
103+
if curve.PointSize() == 32 {
104+
signatureAlgorithm = x509.GOST256
105+
} else {
106+
signatureAlgorithm = x509.GOST512
107+
}
108+
114109
template := x509.Certificate{
115110
SerialNumber: serial,
116111
NotBefore: notBefore,
117112
NotAfter: notAfter,
118-
SignatureAlgorithm: sigAlg,
113+
SignatureAlgorithm: signatureAlgorithm,
119114
Subject: pkix.Name{CommonName: cn},
120115
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
121116
BasicConstraintsValid: true,

common/crypto/sm2/sm2.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ func GenerateCertificate(privKey *sm2.PrivateKey, domain string, isCA bool, expi
6464
Bytes: certDER,
6565
})
6666

67-
// Encode private key
67+
// Encode private key in PKCS8 format for better compatibility
68+
privKeyBytes, err := sm2x509.MarshalSm2UnecryptedPrivateKey(privKey)
69+
if err != nil {
70+
return nil, nil, fmt.Errorf("failed to marshal SM2 private key: %w", err)
71+
}
72+
6873
privKeyPEM := pem.EncodeToMemory(&pem.Block{
6974
Type: "PRIVATE KEY",
70-
Bytes: privKey.D.Bytes(),
75+
Bytes: privKeyBytes,
7176
})
7277

7378
return certPEM, privKeyPEM, nil

0 commit comments

Comments
 (0)