Compare commits

...

93 Commits

Author SHA1 Message Date
5eea527242 add crypt/rsa 2024-04-14 00:11:35 +02:00
bf0dceb985 devops - test webhook 2024-02-14 22:16:09 +01:00
3b893b1a2f devops - drone test build
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-16 00:25:13 +01:00
209d955a29 devops - drone test failure build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-16 00:22:32 +01:00
03921aeb45 devops - drone test failure build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-16 00:20:05 +01:00
2d8e1b42b7 devops - drone test failure build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-16 00:18:37 +01:00
494f48e094 devops - drone test failure build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-16 00:14:06 +01:00
b8369809a2 devops - drone test failure build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-16 00:11:18 +01:00
945c092b61 devops - drone test success build
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-15 01:07:56 +01:00
d85ab069ac devops - drone test success build
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-15 00:44:34 +01:00
dbb1c986eb devops - drone test error build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-15 00:43:00 +01:00
5c0e9bb56f devops - drone test error build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-15 00:37:18 +01:00
81409c8af7 devops - drone test error build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-15 00:36:23 +01:00
55ff2b1929 devops - drone test error build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-15 00:26:17 +01:00
c068d1d96d devops - drone test error build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-15 00:23:41 +01:00
48103111ca devops - drone test error build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-15 00:18:53 +01:00
9697087b6a devops - drone test error build
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-15 00:18:08 +01:00
cdf00a544b devops - drone test error build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-15 00:13:40 +01:00
0edef59781 devops - drone test error build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 23:52:41 +01:00
c869dfc0eb devops - drone test error build
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 23:48:23 +01:00
0081639468 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 23:46:49 +01:00
f092161276 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 23:43:56 +01:00
4548388967 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 23:41:46 +01:00
7441ce3140 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 23:39:55 +01:00
9d82ce5731 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 23:36:48 +01:00
df5de2dac3 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 23:35:55 +01:00
5d46ac12aa devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 23:28:33 +01:00
33cf86942b devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 23:26:11 +01:00
8321968328 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 23:20:59 +01:00
771e28df43 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 23:19:23 +01:00
6b4b4b3466 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-12-14 23:18:56 +01:00
6aa52a16ba devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 23:16:06 +01:00
c017ce159c devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 23:14:23 +01:00
8b89b71975 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 23:12:57 +01:00
4f286c806d devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 23:11:45 +01:00
f3f201be80 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 23:09:04 +01:00
bfcea2ff85 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-12-14 23:07:59 +01:00
fa088c83c7 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-12-14 23:07:35 +01:00
580538e142 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 23:05:00 +01:00
23a02a28db devops - drone test
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-12-14 23:04:06 +01:00
01480124dc devops - drone test
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-12-14 23:02:27 +01:00
df6b6e006f devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 01:54:23 +01:00
0cadeac9e6 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 01:49:38 +01:00
efa57aab20 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 01:45:32 +01:00
457f6d7ddd devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 01:36:52 +01:00
530a353cc8 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 01:35:14 +01:00
1c07082967 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 01:33:04 +01:00
41cd492201 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 01:29:18 +01:00
e5f313bcd5 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 01:27:44 +01:00
123227091e devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 01:23:55 +01:00
3804b08484 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 01:22:13 +01:00
71980977ac devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 01:20:34 +01:00
47609ee00f devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 01:16:34 +01:00
6fe023822a devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 01:14:24 +01:00
7cde6b07ff devops - drone test 2023-12-14 01:10:46 +01:00
2069fd8d17 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 01:08:40 +01:00
7d939c48d9 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 01:07:22 +01:00
1cd9a09d6e devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 01:06:40 +01:00
e98b104683 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 01:00:06 +01:00
31d087b43d devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 00:58:24 +01:00
1a26227897 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 00:52:09 +01:00
a879ba59ff devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 00:50:26 +01:00
f98cfb2f61 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 00:48:18 +01:00
b3d1d1919d devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 00:46:49 +01:00
8fd2d9c801 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 00:46:10 +01:00
ac5fe60856 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 00:20:35 +01:00
57dfd25ae7 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 00:18:37 +01:00
c2e23a4179 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 00:17:06 +01:00
8191d25d93 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 00:13:05 +01:00
cb5ab556b1 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-14 00:11:02 +01:00
eb1a09d86e devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 00:09:25 +01:00
58338504c2 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-13 23:40:29 +01:00
e2830c27a7 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-13 23:39:34 +01:00
8c812ae791 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-13 23:37:36 +01:00
d1d1a5f5a9 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-13 23:35:35 +01:00
9f1c1a78d7 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-13 23:32:16 +01:00
739e3b30b9 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-13 23:31:04 +01:00
3878290860 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-12-13 23:29:37 +01:00
58e228bf69 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-13 23:27:56 +01:00
ca0ea24dc5 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-13 23:26:17 +01:00
76e4a1c1db devops - drone test
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-12-13 23:25:05 +01:00
4adc944019 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-12-13 23:24:08 +01:00
3e52308755 devops - drone test
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-12-13 23:23:21 +01:00
cc6b2dc75d devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-13 23:21:41 +01:00
1a83b7f1bf devops - drone test
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-12-13 23:18:29 +01:00
5ca6644607 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-13 23:09:02 +01:00
1e26944d4e devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-13 22:40:47 +01:00
389b7c5208 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-13 22:36:08 +01:00
9a6c8368e3 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-13 22:35:10 +01:00
7823b2eb89 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-13 22:33:03 +01:00
1dca7e0222 devops - drone test
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-13 22:31:33 +01:00
e3e0638c18 devops - drone test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-12 23:59:18 +01:00
eff5867ddf devops - drone test 2023-12-12 23:55:19 +01:00
4 changed files with 213 additions and 4 deletions

86
.drone.yml Normal file
View File

@ -0,0 +1,86 @@
kind: pipeline
type: docker
name: default
steps:
- name: 2. test
image: golang
volumes:
- name: deps
path: /go
commands:
- go test ./...
- name: 3. build
image: golang
volumes:
- name: deps
path: /go
commands:
- go build -v -race -a ./...
- name: 4. deploy
image: alpine
volumes:
- name: ssh_key
path: /root/.ssh
commands:
- chmod 0400 /root/.ssh/id_rsa.kubehost
- ls -lah /root/.ssh/id_rsa.kubehost
- apk add --no-cache openssh
- ssh -p21022 -o StrictHostKeyChecking=accept-new -i /root/.ssh/id_rsa.kubehost mtc@bosub-kub-int.metacoaching.pro "hostname"
- name: 5. notify fail
image: bash:4.4
environment:
ZULIP_HOST: https://zulip.meta-tech.academy
ZULIP_STREAM: gitea
ZULIP_TOPIC: build
ZULIP_STATUS: ":check:"
ZULIP_USER:
from_secret: ZULIP_BOT
ZULIP_TKN:
from_secret: ZULIP_TOKEN
commands:
- apk add --no-cache curl
- export ZULIP_STATUS=":prohibited:"
- export ZULIP_MESSAGE=$${DRONE_COMMIT_MESSAGE:-2}
- export SHORT_COMMIT=$${DRONE_COMMIT:0:7}
- export REMOTE_URL=$${DRONE_REMOTE_URL:0:-4}
- export REMOTE_URL=$${DRONE_REMOTE_URL:0:-4}
- export ZULIP_FAILED_STEPS=$${DRONE_FAILED_STEPS}
- export FLAG_FAIL=":triangular_flag:"
- curl -s -X POST "$ZULIP_HOST/api/v1/messages" -u "$ZULIP_USER:$ZULIP_TKN" --data-urlencode "type=stream" --data-urlencode "to=\"$ZULIP_STREAM\"" --data-urlencode "topic=$ZULIP_TOPIC" --data "content=$ZULIP_STATUS **[build %23${DRONE_BUILD_NUMBER}](${DRONE_BUILD_LINK})**%0A> **${DRONE_BUILD_EVENT}** event on **${DRONE_COMMIT_BRANCH}** branch *by* **${DRONE_COMMIT_AUTHOR}** ([$SHORT_COMMIT]($REMOTE_URL/commit/${DRONE_COMMIT}))%0A> $ZULIP_MESSAGE%0A> $FLAG_FAIL ***failed at step*** $ZULIP_FAILED_STEPS"
when:
status:
- failure
- name: 5. notify done
image: bash:4.4
environment:
ZULIP_HOST: https://zulip.meta-tech.academy
ZULIP_STREAM: gitea
ZULIP_TOPIC: build
ZULIP_STATUS: ":check:"
ZULIP_USER:
from_secret: ZULIP_BOT
ZULIP_TKN:
from_secret: ZULIP_TOKEN
commands:
- apk add --no-cache curl
- export ZULIP_STATUS=":check:"
- export ZULIP_MESSAGE=$${DRONE_COMMIT_MESSAGE:-2}
- export SHORT_COMMIT=$${DRONE_COMMIT:0:7}
- export REMOTE_URL=$${DRONE_REMOTE_URL:0:-4}
- curl -s -X POST "$ZULIP_HOST/api/v1/messages" -u "$ZULIP_USER:$ZULIP_TKN" --data-urlencode "type=stream" --data-urlencode "to=\"$ZULIP_STREAM\"" --data-urlencode "topic=$ZULIP_TOPIC" --data "content=$ZULIP_STATUS **[build %23${DRONE_BUILD_NUMBER}](${DRONE_BUILD_LINK})**%0A> **${DRONE_BUILD_EVENT}** event on **${DRONE_COMMIT_BRANCH}** branch *by* **${DRONE_COMMIT_AUTHOR}** ([$SHORT_COMMIT]($REMOTE_URL/commit/${DRONE_COMMIT}))%0A> $ZULIP_MESSAGE"
when:
status:
- success
volumes:
- name: deps
temp: {}
- name: ssh_key
host:
path: /home/repo/drone

View File

@ -1,2 +1,4 @@
# core

121
crypt/rsa.go Normal file
View File

@ -0,0 +1,121 @@
package crypt
import (
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"fmt"
"log"
"golang.org/x/crypto/ssh"
)
type RsaEncrypt struct {
pub *rsa.PublicKey
}
func NewRsaEncrypt(key []byte) *RsaEncrypt {
pkey, _, _, _, err := ssh.ParseAuthorizedKey(key)
if err != nil {
log.Fatal("unable to parse authorized key")
}
// upgrade first to ssh.CryptoPublicKey interface
// then call CryptoPublicKey() to get actual crypto.PublicKey
// Finally, convert back to an *rsa.PublicKey
pubCrypto := pkey.(ssh.CryptoPublicKey).CryptoPublicKey()
return &RsaEncrypt{pubCrypto.(*rsa.PublicKey)}
}
func (re *RsaEncrypt) Encrypt(data []byte) (string, error) {
encryptedBytes, err := rsa.EncryptOAEP(
sha256.New(),
rand.Reader,
re.pub,
data,
nil)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(encryptedBytes), nil
}
type RsaKey struct {
priv *rsa.PrivateKey
}
func NewRsaKey(size int) *RsaKey {
key, err := rsa.GenerateKey(rand.Reader, size)
if err != nil {
log.Fatalf("unable to generate key with size %d", size)
}
return &RsaKey{key}
}
func LoadRsaKey(privKey []byte) *RsaKey {
block, _ := pem.Decode(privKey)
key, err := x509.ParsePKCS1PrivateKey(block.Bytes)
key.Size()
if err != nil {
log.Fatal("unable to parse pkcs1 priv key")
}
return &RsaKey{priv: key}
}
func (rk *RsaKey) GetBytes() []byte {
return pem.EncodeToMemory(&pem.Block{
Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(rk.priv),
})
}
func (rk *RsaKey) GetPubKeyBytes() []byte {
pub, err := ssh.NewPublicKey(rk.priv.Public())
if err != nil {
log.Fatal("unable to retriew public key")
}
return ssh.MarshalAuthorizedKey(pub)
}
func (rk *RsaKey) GetRsaEncrypt() *RsaEncrypt {
return &RsaEncrypt{&rk.priv.PublicKey}
}
func (rk *RsaKey) Decrypt(b64data []byte) ([]byte, error) {
data, err := base64.StdEncoding.DecodeString(string(b64data))
if err != nil {
log.Fatal("unable to decode base64 data")
}
decrypted, err := rsa.DecryptOAEP(sha256.New(), rand.Reader, rk.priv, data, nil)
if err != nil {
log.Fatal("unable to decrypt data")
}
return decrypted, nil
}
func mainSshCrypt() {
rk := NewRsaKey(4096)
pubKey := rk.GetPubKeyBytes()
fmt.Println("== PUB KEY ==")
fmt.Println(string(pubKey))
fmt.Println("== PRIV KEY ==")
fmt.Println(string(rk.GetBytes()))
rk2 := LoadRsaKey(rk.GetBytes())
fmt.Println("== LOADED KEY ==")
fmt.Println(string(rk2.GetBytes()))
// fmt.Println("== GET RsaEncrypt ==")
// re := rk.GetRsaEncrypt()
fmt.Println("== NewRsaEncrypt ==")
re := NewRsaEncrypt(pubKey)
fmt.Println("== ENCRYPT data ==")
encryptedData, _ := re.Encrypt([]byte("hello world"))
fmt.Println(encryptedData)
decryptedData, _ := rk.Decrypt([]byte(encryptedData))
fmt.Println("== DECRYPT data ==")
fmt.Println(string(decryptedData))
}

View File

@ -159,7 +159,7 @@ func (s *Ssh) DownloadFile(remoteFile string, localFile string, display bool, cl
if close {
defer scp.Close()
}
if err := s.downloadFile(size, scp, remoteFile, localFile); err == nil {
if err := s.downloadFile(scp, remoteFile, localFile); err == nil {
done = sys.CheckSumFile(checksum, localFile)
if display {
echo.Cstyle("usageCom").Echo(" file downloaded !\n")
@ -177,13 +177,13 @@ func (s *Ssh) DownloadFile(remoteFile string, localFile string, display bool, cl
return done
}
func (s *Ssh) ScpDownload(size int64, remoteFile string, localFile string, close bool) bool {
func (s *Ssh) ScpDownload(remoteFile string, localFile string, close bool) bool {
var done bool = false
scp := s.Scp()
if close {
defer scp.Close()
}
if err := s.downloadFile(size, scp, remoteFile, localFile); err == nil {
if err := s.downloadFile(scp, remoteFile, localFile); err == nil {
done = true
} else {
log.Fatal(err)
@ -191,7 +191,7 @@ func (s *Ssh) ScpDownload(size int64, remoteFile string, localFile string, close
return done
}
func (s *Ssh) downloadFile(size int64, sc *sftp.Client, remoteFile string, localFile string) (err error) {
func (s *Ssh) downloadFile(sc *sftp.Client, remoteFile string, localFile string) (err error) {
// Note: SFTP To Go doesn't support O_RDWR mode
srcFile, err := sc.OpenFile(remoteFile, (os.O_RDONLY))