mirror of
https://git.zx2c4.com/wireguard-windows
synced 2024-11-10 16:59:18 +00:00
6ed37f30f5
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
/* SPDX-License-Identifier: MIT
|
|
*
|
|
* Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"C"
|
|
"crypto/rand"
|
|
"log"
|
|
"path/filepath"
|
|
"unsafe"
|
|
|
|
"golang.org/x/crypto/curve25519"
|
|
"golang.org/x/sys/windows"
|
|
|
|
"golang.zx2c4.com/wireguard/windows/conf"
|
|
"golang.zx2c4.com/wireguard/windows/tunnel"
|
|
)
|
|
|
|
//export WireGuardTunnelService
|
|
func WireGuardTunnelService(confFile16 *uint16) bool {
|
|
confFile := windows.UTF16PtrToString(confFile16)
|
|
conf.PresetRootDirectory(filepath.Dir(confFile))
|
|
tunnel.UseFixedGUIDInsteadOfDeterministic = true
|
|
err := tunnel.Run(confFile)
|
|
if err != nil {
|
|
log.Printf("Service run error: %v", err)
|
|
}
|
|
return err == nil
|
|
}
|
|
|
|
//export WireGuardGenerateKeypair
|
|
func WireGuardGenerateKeypair(publicKey, 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() {}
|