Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Feat: Add a fingerprint to every private key on save, create...

peaklabs-devf9b7841572d5
diff --git a/app/Models/PrivateKey.php b/app/Models/PrivateKey.php
index 45bc6bc847..8682103821 100644
--- a/app/Models/PrivateKey.php
+++ b/app/Models/PrivateKey.php
@@ -26,6 +26,7 @@ class PrivateKey extends BaseModel
'name',
'description',
'private_key',
+ 'fingerprint',
'is_git_related',
'team_id',
];
@@ -35,10 +36,10 @@ class PrivateKey extends BaseModel
static::saving(function ($key) {
$privateKey = data_get($key, 'private_key');
if (substr($privateKey, -1) !== "\n") {
- $key->private_key = $privateKey."\n";
+ $key->private_key = $privateKey . "\n";
}
+ $key->fingerprint = $key->generateFingerprint();
});
-
}
public static function ownedByCurrentTeam(array $select = ['*'])
@@ -85,4 +86,14 @@ class PrivateKey extends BaseModel
{
return $this->hasMany(GitlabApp::class);
}
+
+ public function generateFingerprint()
+ {
+ try {
+ $key = PublicKeyLoader::load($this->private_key);
+ return $key->getPublicKey()->getFingerprint('sha256');
+ } catch (\Throwable $e) {
+ return 'invalid_' . md5($this->private_key); // TODO: DO NOT ALLOW SAVING IF INVALID SSH KEYS SAY SSH KEY IS INVALID
+ }
+ }
}