-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated code lifecycle: Show ssh fingerprints (#9650)
- Loading branch information
1 parent
2fa027e
commit ab8bada
Showing
18 changed files
with
443 additions
and
7 deletions.
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
...e/tum/cit/aet/artemis/programming/service/localvc/ssh/SshFingerprintsProviderService.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package de.tum.cit.aet.artemis.programming.service.localvc.ssh; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_LOCALVC; | ||
|
||
import java.io.IOException; | ||
import java.security.GeneralSecurityException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import jakarta.ws.rs.BadRequestException; | ||
|
||
import org.apache.sshd.common.keyprovider.KeyPairProvider; | ||
import org.apache.sshd.server.SshServer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Service responsible for providing SSH fingerprints of the SSH server running in Artemis. | ||
*/ | ||
@Profile(PROFILE_LOCALVC) | ||
@Service | ||
public class SshFingerprintsProviderService { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(SshFingerprintsProviderService.class); | ||
|
||
private final SshServer sshServer; | ||
|
||
public SshFingerprintsProviderService(SshServer sshServer) { | ||
this.sshServer = sshServer; | ||
} | ||
|
||
/** | ||
* Retrieves the SSH key fingerprints from the stored SSH keys | ||
* | ||
* @return a map containing the SSH key fingerprints, where the key is the algorithm | ||
* of the public key and the value is its SHA-256 fingerprint. | ||
* @throws BadRequestException if there is an error loading keys from the SSH server. | ||
*/ | ||
public Map<String, String> getSshFingerPrints() { | ||
Map<String, String> fingerprints = new HashMap<>(); | ||
KeyPairProvider keyPairProvider = sshServer.getKeyPairProvider(); | ||
if (keyPairProvider != null) { | ||
try { | ||
keyPairProvider.loadKeys(null).iterator() | ||
.forEachRemaining(keyPair -> fingerprints.put(keyPair.getPublic().getAlgorithm(), HashUtils.getSha256Fingerprint(keyPair.getPublic()))); | ||
|
||
} | ||
catch (IOException | GeneralSecurityException e) { | ||
log.info("Could not load keys from the ssh server while trying to get SSH key fingerprints", e); | ||
throw new BadRequestException("Could not load keys from the ssh server"); | ||
} | ||
} | ||
return fingerprints; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...a/de/tum/cit/aet/artemis/programming/web/localvc/ssh/SshFingerprintsProviderResource.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package de.tum.cit.aet.artemis.programming.web.localvc.ssh; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_LOCALVC; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import de.tum.cit.aet.artemis.core.security.annotations.EnforceAtLeastStudent; | ||
import de.tum.cit.aet.artemis.programming.service.localvc.ssh.SshFingerprintsProviderService; | ||
|
||
/** | ||
* REST controller for managing. | ||
*/ | ||
@Profile(PROFILE_LOCALVC) | ||
@RestController | ||
@RequestMapping("api/") | ||
public class SshFingerprintsProviderResource { | ||
|
||
SshFingerprintsProviderService sshFingerprintsProviderService; | ||
|
||
public SshFingerprintsProviderResource(SshFingerprintsProviderService sshFingerprintsProviderService) { | ||
this.sshFingerprintsProviderService = sshFingerprintsProviderService; | ||
} | ||
|
||
/** | ||
* GET /ssh-fingerprints | ||
* | ||
* @return the SSH fingerprints for the keys a user uses | ||
*/ | ||
@GetMapping(value = "ssh-fingerprints", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@EnforceAtLeastStudent | ||
public ResponseEntity<Map<String, String>> getSshFingerprints() { | ||
return ResponseEntity.ok().body(sshFingerprintsProviderService.getSshFingerPrints()); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...red/user-settings/ssh-settings/fingerprints/ssh-user-settings-fingerprints.component.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<h1 jhiTranslate="artemisApp.userSettings.sshSettingsPage.sshFingerprints"></h1> | ||
|
||
<div class="list-group d-block"> | ||
<!-- Viewing existing key and creating a new key --> | ||
<div class="list-group-item"> | ||
<div class="d-flex flex-wrap"> | ||
<p class="font-medium"> | ||
<span class="mt-4" jhiTranslate="artemisApp.userSettings.sshSettingsPage.fingerprintsExplanation"> </span> | ||
<jhi-documentation-link [documentationType]="documentationType" [displayString]="'artemisApp.userSettings.sshSettingsPage.fingerprintsLearnMore'"> | ||
</jhi-documentation-link> | ||
</p> | ||
</div> | ||
|
||
@if (sshFingerprints && sshFingerprints['RSA']) { | ||
<div class="row small-text"> | ||
<div class="column left"> | ||
{{ 'RSA' }} | ||
</div> | ||
<div class="column right"> | ||
{{ sshFingerprints['RSA'] }} | ||
</div> | ||
</div> | ||
} | ||
|
||
@if (sshFingerprints && sshFingerprints['EdDSA']) { | ||
<div class="row small-text"> | ||
<div class="column left"> | ||
{{ 'ED25519' }} | ||
</div> | ||
<div class="column right"> | ||
{{ sshFingerprints['EdDSA'] }} | ||
</div> | ||
</div> | ||
} | ||
|
||
@if (sshFingerprints && sshFingerprints['ECDSA']) { | ||
<div class="row"> | ||
<div class="column left"> | ||
{{ 'ECDSA' }} | ||
</div> | ||
<div class="column right"> | ||
{{ sshFingerprints['ECDSA'] }} | ||
</div> | ||
</div> | ||
} | ||
|
||
@if (sshFingerprints && sshFingerprints['EC']) { | ||
<div class="row"> | ||
<div class="column left"> | ||
{{ 'ECDSA' }} | ||
</div> | ||
<div class="column right"> | ||
{{ sshFingerprints['EC'] }} | ||
</div> | ||
</div> | ||
} | ||
|
||
<div class="d-flex justify-content-between align-items-center mt-4"> | ||
<div></div> | ||
<div> | ||
<a class="btn rounded-btn btn-primary btn-sm" [routerLink]="['..']"> | ||
<span class="jhi-btn__title" style="font-size: small" jhiTranslate="artemisApp.userSettings.sshSettingsPage.back"></span> | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
12 changes: 12 additions & 0 deletions
12
...red/user-settings/ssh-settings/fingerprints/ssh-user-settings-fingerprints.component.scss
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.column { | ||
float: left; | ||
padding: 10px; | ||
} | ||
|
||
.left { | ||
width: 15%; | ||
} | ||
|
||
.right { | ||
width: 85%; | ||
} |
24 changes: 24 additions & 0 deletions
24
...hared/user-settings/ssh-settings/fingerprints/ssh-user-settings-fingerprints.component.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Component, OnInit, inject } from '@angular/core'; | ||
import { ButtonSize, ButtonType } from 'app/shared/components/button.component'; | ||
import { DocumentationType } from 'app/shared/components/documentation-button/documentation-button.component'; | ||
import { SshUserSettingsFingerprintsService } from 'app/shared/user-settings/ssh-settings/fingerprints/ssh-user-settings-fingerprints.service'; | ||
|
||
@Component({ | ||
selector: 'jhi-account-information', | ||
templateUrl: './ssh-user-settings-fingerprints.component.html', | ||
styleUrls: ['./ssh-user-settings-fingerprints.component.scss', '../ssh-user-settings.component.scss'], | ||
}) | ||
export class SshUserSettingsFingerprintsComponent implements OnInit { | ||
readonly sshUserSettingsService = inject(SshUserSettingsFingerprintsService); | ||
|
||
protected sshFingerprints?: { [key: string]: string }; | ||
|
||
readonly documentationType: DocumentationType = 'SshSetup'; | ||
protected readonly ButtonType = ButtonType; | ||
|
||
protected readonly ButtonSize = ButtonSize; | ||
|
||
async ngOnInit() { | ||
this.sshFingerprints = await this.sshUserSettingsService.getSshFingerprints(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
.../shared/user-settings/ssh-settings/fingerprints/ssh-user-settings-fingerprints.service.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Injectable, inject } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { firstValueFrom } from 'rxjs'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class SshUserSettingsFingerprintsService { | ||
error?: string; | ||
|
||
private http = inject(HttpClient); | ||
|
||
public async getSshFingerprints(): Promise<{ [key: string]: string }> { | ||
return await firstValueFrom(this.http.get<{ [key: string]: string }>('api/ssh-fingerprints')); | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.