-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutils.go
More file actions
91 lines (73 loc) · 1.81 KB
/
utils.go
File metadata and controls
91 lines (73 loc) · 1.81 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"bytes"
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha1"
"crypto/x509"
"encoding/json"
"encoding/pem"
"log"
"os"
"github.com/getsentry/sentry-go"
"github.com/logrusorgru/aurora/v4"
)
type CountryConfig struct {
CountryCode uint8 `json:"countryCode"`
LanguageCode uint8 `json:"languageCode"`
Name string `json:"name"`
Language string `json:"language"`
Source string `json:"source"`
}
type Countries struct {
Countries []CountryConfig `json:"countries"`
}
func LoadCountries(filename string) (*Countries, error) {
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
var countries Countries
err = json.Unmarshal(data, &countries)
if err != nil {
return nil, err
}
return &countries, nil
}
// fixTime adjusts the timestamp to coincide with the Wii's UTC timestamp.
func fixTime(value int) uint32 {
return uint32((value - 946684800) / 60)
}
func SignFile(contents []byte, test bool) []byte {
buffer := new(bytes.Buffer)
// Get RSA key and sign
var rsaData []byte
var err error
if test {
rsaData, err = os.ReadFile("sample.pem")
} else {
rsaData, err = os.ReadFile("Private.pem")
}
checkError(err)
rsaBlock, _ := pem.Decode(rsaData)
parsedKey, err := x509.ParsePKCS1PrivateKey(rsaBlock.Bytes)
checkError(err)
// Hash our data then sign
hash := sha1.New()
_, err = hash.Write(contents)
checkError(err)
contentsHashSum := hash.Sum(nil)
reader := rand.Reader
signature, err := rsa.SignPKCS1v15(reader, parsedKey, crypto.SHA1, contentsHashSum)
checkError(err)
buffer.Write(make([]byte, 64))
buffer.Write(signature)
buffer.Write(contents)
return buffer.Bytes()
}
// ReportError reports errors to Sentry
func ReportError(err error) {
sentry.CaptureException(err)
log.Printf("An error has occurred: %s", aurora.Red(err.Error()))
}