Skip to content

Commit

Permalink
To revert
Browse files Browse the repository at this point in the history
Signed-off-by: tobias.pobocik <[email protected]>
  • Loading branch information
Tobianas committed Mar 18, 2024
1 parent c54ba99 commit d3d5304
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ public byte[] encrypt(byte[] data) {
public byte[] decrypt(byte[] encryptedData) {
if (encryptedData != null && encryptedData.length != 0) {
try {
return decryptCipher.doFinal(encryptedData);
int blockSize = encryptCipher.getBlockSize();
int paddingLength = blockSize - (encryptedData.length % blockSize);
byte[] paddedData = new byte[encryptedData.length + paddingLength];
System.arraycopy(encryptedData, 0, paddedData, 0, encryptedData.length);
byte paddingByte = (byte) (paddingLength & 0xFF);
for (int i = encryptedData.length; i < paddedData.length; i++) {
paddedData[i] = paddingByte;
}

return decryptCipher.doFinal(paddedData);
} catch (IllegalBlockSizeException | BadPaddingException e) {
LOG.error("Failed to decrypt encoded data", e);
return encryptedData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private TestUtils() {
}

public static SessionManager createSessionManagerWithCerts() throws Exception {
final KeyPair keyPair = AAAConfigUtils.decodePrivateKey(new StringReader(readResource(CLIENT_KEY)).toString(), PASSPHRASE);
final KeyPair keyPair = AAAConfigUtils.decodePrivateKey(readResource(CLIENT_KEY).toString(), PASSPHRASE);
final Security gnmiSecurity = SecurityFactory.createGnmiSecurity(readResource(CA_CERTS),
readResource(CLIENT_CERTS), keyPair.getPrivate());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private Optional<GnmiYangModel> tryToReadModel(final GnmiDeviceCapability capabi
gnmiYangModel.getVersion().getValue()));
}
} else {
readImport = yangDataStoreService.readYangModel(capability.getName())
readImport = yangDataStoreService.readYangModel(capability.toString())
.get(TimeoutUtils.DATASTORE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
}

Expand Down Expand Up @@ -227,14 +227,8 @@ public EffectiveModelContext getSchemaContext(final List<GnmiDeviceCapability> c
}

private DelegatedYangTextSource makeTextSchemaSource(final GnmiYangModel model) {
if (model.getVersion().getValue().matches(SchemaConstants.REVISION_REGEX)) {
return new DelegatedYangTextSource(
new SourceIdentifier(UnresolvedQName.Unqualified.of(model.getName()),
Revision.of(model.getVersion().getValue())), bodyCharSource(model.getBody()));
} else {
return new DelegatedYangTextSource(new SourceIdentifier(model.getName()),
bodyCharSource(model.getBody()));
}
return new DelegatedYangTextSource(
new SourceIdentifier(model.getName()), bodyCharSource(model.getBody()));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public YangLoadModelUtil(final YangTextSource yangTextSchemaSource, final InputS
.orElse(null);
this.modelSemVer = semanticVersion.orElse(null);
this.modelBody = IOUtils.toString(yangTextStream, StandardCharsets.UTF_8);
this.modelName = yangModelDependencyInfo.sourceId().toYangFilename();
this.modelName = yangModelDependencyInfo.sourceId().name().getLocalName();
}

public String getVersionToStore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@
import io.lighty.modules.gnmi.connector.session.api.SessionProviderImpl;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.util.Arrays;
import java.util.Base64;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
Expand All @@ -52,6 +55,7 @@
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.util.Bytes;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -416,7 +420,8 @@ private static Keystore getKeystore1WithPassResponse() {
return new KeystoreBuilder()
.setCaCertificate(getResource(CA_CRT))
.setClientCert(getResource(CLIENT_ENCRYPTED_CRT))
.setClientKey(new String(AAA_ENCRYPTION_SERVICE.encrypt(getResource(CLIENT_ENCRYPTED_KEY).getBytes())))
.setClientKey(new String(AAA_ENCRYPTION_SERVICE.encrypt(getResource(CLIENT_ENCRYPTED_KEY).getBytes(
Charset.defaultCharset()))))
.setPassphrase(new String(AAA_ENCRYPTION_SERVICE.encrypt(PASSPHRASE.getBytes())))
.setKeystoreId(KEYSTORE_PASSPHRASE_ID_1)
.build();
Expand All @@ -426,7 +431,7 @@ private static Keystore getKeystore2Response() {
return new KeystoreBuilder()
.setCaCertificate(getResource(CA_CRT))
.setClientCert(getResource(CLIENT_CRT))
.setClientKey(new String(AAA_ENCRYPTION_SERVICE.encrypt(getResource(CLIENT_KEY).getBytes())))
.setClientKey(new String(AAA_ENCRYPTION_SERVICE.encrypt((getResource(CLIENT_KEY).getBytes())), StandardCharsets.UTF_8))
.setKeystoreId(KEYSTORE_ID_2)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ListenableFuture<Optional<GnmiYangModel>> readYangModel(final String mode
public ListenableFuture<Optional<GnmiYangModel>> readYangModel(final String modelName) {
final List<Map.Entry<ImmutablePair<String, String>, String>> entriesWithRequestedName =
yangs.entrySet().stream()
.filter(e -> e.getKey().left.equals(modelName))
.filter(e -> e.getKey().getLeft().equals(modelName))
.collect(Collectors.toList());

if (entriesWithRequestedName.size() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void loadTopLevelSingleNodeModelsFromJsonConfig() throws Exception {
final int loadedModulesSize = lightyController.getServices().getEffectiveModelContext().getModules().size();
assertTrue(lightyController.shutdown(TIME_OUT, TimeUnit.SECONDS));

assertEquals(loadedModulesSize, 17);
assertEquals(loadedModulesSize, 14);
}

@Test
Expand All @@ -43,7 +43,7 @@ public void loadTopLevelClusterModelsFromJsonConfig() throws Exception {
final int loadedModulesSize = lightyController.getServices().getEffectiveModelContext().getModules().size();
assertTrue(lightyController.shutdown(TIME_OUT, TimeUnit.SECONDS));

assertEquals(loadedModulesSize, 17);
assertEquals(loadedModulesSize, 14);
}

private LightyController getLightyController(final String resource) throws Exception {
Expand Down

0 comments on commit d3d5304

Please sign in to comment.