Skip to content

Commit

Permalink
Modify API and service
Browse files Browse the repository at this point in the history
  • Loading branch information
swarup-n committed Nov 24, 2024
1 parent d6c1559 commit 9d9ff9e
Show file tree
Hide file tree
Showing 28 changed files with 64 additions and 134 deletions.
2 changes: 1 addition & 1 deletion distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.yamcs</groupId>
<artifactId>yamcs</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>distribution</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/cascading/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>cascading</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/ccsds-frames/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>ccsds-frames</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/cfdp-udp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>cfdp-udp</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/cfdp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>cfdp</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/perftest1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>perftest1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/perftest2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>perftest2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs</groupId>
<artifactId>yamcs</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<groupId>org.yamcs.examples</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/pus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>pus</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/replication1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>replication1</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/replication2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>replication2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/replication3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>replication3</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/simulation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>simulation</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>snippets</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/templates/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs.examples</groupId>
<artifactId>examples</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>templates</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion packet-viewer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.yamcs</groupId>
<artifactId>yamcs</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>packet-viewer</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.yamcs</groupId>
<artifactId>yamcs</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>

<packaging>pom</packaging>

Expand Down
2 changes: 1 addition & 1 deletion simulator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yamcs</groupId>
<artifactId>yamcs</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>simulator</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.yamcs</groupId>
<artifactId>yamcs</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>tests</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion yamcs-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.yamcs</groupId>
<artifactId>yamcs</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>yamcs-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ message UpdateKeyResponse {

// Type of the key
optional string keyFamily = 2;

// Error message
optional string error = 3;
}

message ActiveKeyRequest {
Expand Down
2 changes: 1 addition & 1 deletion yamcs-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.yamcs</groupId>
<artifactId>yamcs</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>yamcs-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion yamcs-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.yamcs</groupId>
<artifactId>yamcs</artifactId>
<version>5.10.8-Pixxel-5.7.0-keySwarup4</version>
<version>5.10.8-Pixxel-5.7.0-keySwarup5</version>
</parent>

<artifactId>yamcs-core</artifactId>
Expand Down
96 changes: 24 additions & 72 deletions yamcs-core/src/main/java/org/yamcs/http/api/KeyManagementApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,88 +10,38 @@
import org.yamcs.security.SystemPrivilege;
import org.yamcs.security.encryption.aes.KeyManagementService;
import org.yamcs.time.TimeService;
import org.yamcs.yarch.DataType;
import org.yamcs.yarch.Stream;
import org.yamcs.yarch.StreamSubscriber;
import org.yamcs.yarch.Tuple;
import org.yamcs.yarch.TupleDefinition;


public class KeyManagementApi extends AbstractKeyManagmentApi<Context>{
private static final Log log = new Log(KeyManagementApi.class);

public static final Pattern ALLOWED_INSTANCE_NAMES = Pattern.compile("\\w[\\w\\.-]*");

// @Override
// public void updateKey(Context ctx, UpdateKeyRequest request, Observer<UpdateKeyResponse> observer) {
// ctx.checkSystemPrivilege(SystemPrivilege.ControlServices);

// KeyManagementService keyMgmService = YamcsServer.getServer().getInstance(request.getInstance()).getService(KeyManagementService.class, "keyManagementService");
// TimeService timeService = YamcsServer.getTimeService(request.getInstance());

// Stream responseStream = StreamFactory.asyncResponse(request.getInstance(), KeyManagementService.KEY_INSERTION_RESPONSE_TUPLE_DEFINITION.copy());
// responseStream.addSubscriber(new StreamSubscriber() {
// @Override
// public void onTuple(Stream stream, Tuple t) {
// boolean status = (Boolean) t.getBooleanColumn("status");

// UpdateKeyResponse.Builder updateKeyResponse = UpdateKeyResponse.newBuilder();

// if (status) {
// String keyId = (String) t.getColumn("keyid");
// String family = (String) t.getColumn("family");

// updateKeyResponse.setKeyFamily(family).setKeyId(keyId);

// } else {
// String error = (String) t.getColumn("error");
// updateKeyResponse.setError(error);
// }

// // Send response
// observer.complete(updateKeyResponse.build());

// // Close temporary HTML stream
// stream.close();
// }
// });


// // Add temporary column
// TupleDefinition modTd = KeyManagementService.ACTIVE_KEY_TUPLE_DEFINITION.copy();
// modTd.addColumn("responsestream", DataType.STRING);

// Stream publishStream = keyMgmService.getStream();
// publishStream.emitTuple(new Tuple(KeyManagementService.ACTIVE_KEY_TUPLE_DEFINITION, new Object[]{
// timeService.getMissionTime(),
// request.getKeyId(),
// request.getKeyFamily(),
// responseStream.getName()
// })
// );
// }


@Override
public void updateKey(Context ctx, UpdateKeyRequest request, Observer<UpdateKeyResponse> observer) {
ctx.checkSystemPrivilege(SystemPrivilege.ControlServices);

KeyManagementService keyMgmService = YamcsServer.getServer().getInstance(request.getInstance()).getService(KeyManagementService.class, "keyManagementService");
TimeService timeService = YamcsServer.getTimeService(request.getInstance());

Stream stream = keyMgmService.getStream();

try {
Tuple t = new Tuple(KeyManagementService.ACTIVE_KEY_TUPLE_DEFINITION, new Object[]{
Stream publishStream = keyMgmService.getStream();
publishStream.emitTuple(new Tuple(KeyManagementService.ACTIVE_KEY_TUPLE_DEFINITION, new Object[]{
timeService.getMissionTime(),
request.getKeyId(),
request.getKeyFamily(),
});
stream.emitTuple(t);
})
);

UpdateKeyResponse.Builder updateKeyResponse = UpdateKeyResponse.newBuilder();
updateKeyResponse.setKeyId(request.getKeyId());
updateKeyResponse
.setKeyFamily(request.getKeyFamily())
.setKeyId(request.getKeyId());

observer.complete(updateKeyResponse.build());
} catch (Exception e){
} catch (RuntimeException e) {
log.warn("Error while updating key: {}", e);
observer.completeExceptionally(e);
}
Expand All @@ -100,23 +50,25 @@ public void updateKey(Context ctx, UpdateKeyRequest request, Observer<UpdateKeyR
@Override
public void getActiveKey(Context ctx, ActiveKeyRequest request, Observer<ActiveKeyResponse> observer) {
ctx.checkSystemPrivilege(SystemPrivilege.ControlServices);

KeyManagementService keyMgmService = YamcsServer.getServer().getInstance(request.getInstance()).getService(KeyManagementService.class, "keyManagementService");

String keyId;
try {
ActiveKeyResponse.Builder activeKeyResponse = ActiveKeyResponse.newBuilder();
if (request.getFamily().equals("tm")) {
activeKeyResponse.setKeyId(keyMgmService.getTmKeyId());
} else if(request.getFamily().equals("tc")) {
activeKeyResponse.setKeyId(keyMgmService.getTcKeyId());
} else if((request.getFamily().equals("pay"))){
activeKeyResponse.setKeyId(keyMgmService.getPayloadKeyId());
} else{
activeKeyResponse.setKeyId("family not found");
switch (request.getFamily()) {
case "tm" -> keyId = keyMgmService.getTmKeyId();
case "tc" -> keyId = keyMgmService.getTcKeyId();
case "pay" -> keyId = keyMgmService.getPayloadKeyId();
default -> keyId = "family not found";
}
activeKeyResponse.setFamily(request.getFamily());
activeKeyResponse.setInstance(request.getInstance());

ActiveKeyResponse.Builder activeKeyResponse = ActiveKeyResponse.newBuilder();
activeKeyResponse
.setFamily(request.getFamily())
.setInstance(request.getInstance())
.setKeyId(keyId);

observer.complete(activeKeyResponse.build());

} catch (Exception e){
log.warn("Error while updating key: {}", e);
observer.completeExceptionally(e);
Expand Down
Loading

0 comments on commit 9d9ff9e

Please sign in to comment.