This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAQEegZ89+oYcWf8le3SxyvSdiQUhkp5SfhUdltf78lxWlUVnHrsfLfRfAX2CnRKndnXjKj0ScaAGq2+duqKVTyVQrqtYvb9xC7kQMwMq2Z0SjPATN1EaKm6FQnLAZsw4Q6uKEuXVCEQ0s7bbz3z8f6YXG3sAno8cciuLDTiMjtu/O/71yfrRmG29vs5kvl/k1lX9OfquWlHIOhjREO3y0BNN9K6WjnCgAdEsJZdJ+PPTFq/2ciWqrVxi29ooGZ4lhmUDAzJnSD4btHjuh33FnuDGi7IfHbX9jOUsxRyDG+huwh3hSP/gV4Va1jdBqijswha9uWAwioA0HyLMgrmqD rkovacs@Richard-Kovacs-MBP.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rawSign - base64 encoded representation of the signiture | |
// pubPem - public key in PEM format | |
// data - the signed data | |
func CheckSignature(rawSign string, pubPem []byte, data []byte) bool { | |
var err error | |
var sign []byte | |
var pub interface{} | |
sign, err = base64.StdEncoding.DecodeString(rawSign) | |
if err == nil { | |
block, _ := pem.Decode(pubPem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Wrap(handler func(w http.ResponseWriter, req *http.Request), signatureKey []byte) http.Handler { | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
body := new(bytes.Buffer) | |
defer r.Body.Close() | |
ioutil.ReadAll(io.TeeReader(r.Body, body)) | |
r.Body = ioutil.NopCloser(body) // We read the body twice, we have to wrap original ReadCloser | |
signature := strings.TrimSpace(r.Header.Get("signature")) | |
if err := CheckSignature(signature, signatureKey, body.Bytes()); err != nil { | |
// Error handling | |
w.WriteHeader(http.StatusNotAcceptable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func PostItHandler(w http.ResponseWriter, req *http.Request) { | |
w.Write([]byte("ok")) | |
} | |
func RegisterHandler() { | |
signature, _ := ioutil.ReadFile("/path/of/public/key") | |
r := mux.NewRouter() | |
r.Handle("/postit", Wrap(PostItHandler, signature)).Methods("POST") | |
http.Handle("/", r) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type TestWriter struct { | |
header http.Header | |
status int | |
message string | |
} | |
func (w *TestWriter) Header() http.Header { | |
return w.header | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// privateKeyPem - private key in PEM format | |
// data - data to signature | |
public static String generateSignature(String privateKeyPem, byte[] data) { | |
try (PEMParser pEMParser = new PEMParser(new StringReader(clarifyPemKey(privateKeyPem)))) { | |
PEMKeyPair pemKeyPair = (PEMKeyPair) pEMParser.readObject(); | |
KeyFactory factory = KeyFactory.getInstance("RSA"); | |
X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(pemKeyPair.getPublicKeyInfo().getEncoded()); | |
PublicKey publicKey = factory.generatePublic(publicKeySpec); | |
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(pemKeyPair.getPrivateKeyInfo().getEncoded()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
"math/rand" | |
"sync" | |
"sync/atomic" | |
"time" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
c := make(chan bool) | |
go func() { c <- true }() | |
println(<-c) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
"math/rand" | |
"sync" | |
"sync/atomic" | |
"time" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var itsLast, notLast int32 // statisztika eredménye | |
countChan := make(chan int, COUNTERS) // chanel, amin a számláló várja az értékeket | |
counter := func() { | |
for { | |
e := <-countChan // kiolvassuk a következő értéket | |
mtx.RLock() // olvasásra zárolunk és kiolvassuk az eredmenyből az utolsó elemet | |
last := results[len(results)-1] | |
mtx.RUnlock() |
OlderNewer