blob: b2e02fa46730e7208e8341f076d1504be0ccb566 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
*/
package main
import (
"C"
"golang.org/x/crypto/curve25519"
"golang.org/x/sys/windows"
"golang.zx2c4.com/wireguard/windows/conf"
"golang.zx2c4.com/wireguard/windows/tunnel"
"crypto/rand"
"log"
"path/filepath"
"unsafe"
)
func init() {
tunnel.ForceImplementation = 1
tunnel.UseFixedGUIDInsteadOfDeterministic = true
}
//export WireGuardForceLegacyImplementation
func WireGuardForceLegacyImplementation(useOldCode bool) {
if useOldCode {
tunnel.ForceImplementation = 2
} else {
tunnel.ForceImplementation = 1
}
}
//export WireGuardTunnelService
func WireGuardTunnelService(confFile16 *uint16) bool {
confFile := windows.UTF16PtrToString(confFile16)
conf.PresetRootDirectory(filepath.Dir(confFile))
err := tunnel.Run(confFile)
if err != nil {
log.Printf("Service run error: %v", err)
}
return err == nil
}
//export WireGuardGenerateKeypair
func WireGuardGenerateKeypair(publicKey *byte, privateKey *byte) {
publicKeyArray := (*[32]byte)(unsafe.Pointer(publicKey))
privateKeyArray := (*[32]byte)(unsafe.Pointer(privateKey))
n, err := rand.Read(privateKeyArray[:])
if err != nil || n != len(privateKeyArray) {
panic("Unable to generate random bytes")
}
privateKeyArray[0] &= 248
privateKeyArray[31] = (privateKeyArray[31] & 127) | 64
curve25519.ScalarBaseMult(publicKeyArray, privateKeyArray)
}
func main() {}
|