PGP encryption with multiple keys in mule - encryption

Given that PGP supports encryption using multiple public keys, how it can be achieved in mulesoft?
adding two keys in Public Key Ring File Name field on encryption config window for pgp encrypter tab results in error as org.mule.module.pgp.exception.MissingPGPKeyException: No key file found in: abc.gpg,test.pgp
Is it possible to add multiple public keys from this encrypt module or else how it can be done? mule runtime : 3.8.5
much appreciate any help. Thank you!

I solved this by using java component- invoking terminal and running gpg encrypt command from java runtime. I am just checking for OS first to build a command string to run its respective terminal
boolean isWindows = System.getProperty("os.name")
.toLowerCase().startsWith("windows");
/*gpg command options may vary as per your requirement. multiple --recipient option here is the way to encrypt with multiple public keys.
Using StringBuilder helps to build this string from input/dynamic values.
*/
String command = "gpg --pgp6 --armor --batch --output encryptedHelloWorld.pgp --trust-model always --recipient "<part of UserID1 (either name or emailId)>" --recipient "<part of UserID2>" --encrypt helloWorld.txt"
/*in case you need to change directory to where your file is to encrypt it from one command, you could append this
`"cd"+ <your path to file> "&" + command` ----> for windows
`"cd"+ <your path to file> ";" + command` ----> for linux
*/
public int executeCommand(String command) throws IOException, InterruptedException {
Process pr;
if (isWindows) {
String[] cmd = { "cmd.exe", "/c", command };
pr = Runtime.getRuntime().exec(cmd);
}
else {
String[] cmd = { "/bin/sh", "-c", command };
pr = Runtime.getRuntime().exec(cmd);
}
int exitStatus = pr.waitFor(); // this gives you value 0 if success or other than 0 which ties to error message
errorInputStream = pr.getErrorStream(); //streaming error message
return exitStatus;
}

Related

path not being detected by Nextflow

i'm new to nf-core/nextflow and needless to say the documentation does not reflect what might be actually implemented. But i'm defining the basic pipeline below:
nextflow.enable.dsl=2
process RUNBLAST{
input:
val thr
path query
path db
path output
output:
path output
script:
"""
blastn -query ${query} -db ${db} -out ${output} -num_threads ${thr}
"""
}
workflow{
//println "I want to BLAST $params.query to $params.dbDir/$params.dbName using $params.threads CPUs and output it to $params.outdir"
RUNBLAST(params.threads,params.query,params.dbDir, params.output)
}
Then i'm executing the pipeline with
nextflow run main.nf --query test2.fa --dbDir blast/blastDB
Then i get the following error:
N E X T F L O W ~ version 22.10.6
Launching `main.nf` [dreamy_hugle] DSL2 - revision: c388cf8f31
Error executing process > 'RUNBLAST'
Error executing process > 'RUNBLAST'
Caused by:
Not a valid path value: 'test2.fa'
Tip: you can replicate the issue by changing to the process work dir and entering the command bash .command.run
I know test2.fa exists in the current directory:
(nfcore) MN:nf-core-basicblast jraygozagaray$ ls
CHANGELOG.md conf other.nf
CITATIONS.md docs pyproject.toml
CODE_OF_CONDUCT.md lib subworkflows
LICENSE main.nf test.fa
README.md modules test2.fa
assets modules.json work
bin nextflow.config workflows
blast nextflow_schema.json
I also tried with "file" instead of path but that is deprecated and raises other kind of errors.
It'll be helpful to know how to fix this to get myself started with the pipeline building process.
Shouldn't nextflow copy the file to the execution path?
Thanks
You get the above error because params.query is not actually a path value. It's probably just a simple String or GString. The solution is to instead supply a file object, for example:
workflow {
query = file(params.query)
BLAST( query, ... )
}
Note that a value channel is implicitly created by a process when it is invoked with a simple value, like the above file object. If you need to be able to BLAST multiple query files, you'll instead need a queue channel, which can be created using the fromPath factory method, for example:
params.query = "${baseDir}/data/*.fa"
params.db = "${baseDir}/blastdb/nt"
params.outdir = './results'
db_name = file(params.db).name
db_path = file(params.db).parent
process BLAST {
publishDir(
path: "{params.outdir}/blast",
mode: 'copy',
)
input:
tuple val(query_id), path(query)
path db
output:
tuple val(query_id), path("${query_id}.out")
"""
blastn \\
-num_threads ${task.cpus} \\
-query "${query}" \\
-db "${db}/${db_name}" \\
-out "${query_id}.out"
"""
}
workflow{
Channel
.fromPath( params.query )
.map { file -> tuple(file.baseName, file) }
.set { query_ch }
BLAST( query_ch, db_path )
}
Note that the usual way to specify the number of threads/cpus is using cpus directive, which can be configured using a process selector in your nextflow.config. For example:
process {
withName: BLAST {
cpus = 4
}
}

Paramiko No such file or directory: '-----BEGIN RSA PRIVATE KEY-----\n'

I am coming across issues using the SSHHook class in a DAG.
The error is
File "/usr/local/airflow/.local/lib/python3.7/site-packages/paramiko/pkey.py", line 307, in _read_private_key_file
with open(filename, "r") as f:
FileNotFoundError: [Errno 2] No such file or directory: '-----BEGIN RSA PRIVATE KEY-----\n'
What I am doing is taking a PEM key from AWS Secrets Manager and writing it to a file-like object using StringIO.
secrets_manager_hook = SecretsManagerHook()
sm_client = secrets_manager_hook.get_conn()
secret = sm_client.get_secret_value(SecretId='<SECRET>')
pem_key_value = secret["SecretString"]
with StringIO(initial_value=pem_key_value) as pem_file:
ssh_hook=SSHHook(ssh_conn_id=None, remote_host=<HOST>, username='ec2-user', key_file=pem_file)
ssh_hook_conn=ssh_hook.get_conn()
ssh_hook.exec_ssh_client_command(ssh_client=ssh_hook_conn, command='echo Hello', get_pty=False)
My PEM key that I uploaded as just a plain text secret looks like this
-----BEGIN RSA PRIVATE KEY-----
######
...
...
######
-----END RSA PRIVATE KEY-----
If I print the secret value retrieved from the Boto3 client it is a similar output.
I'm not sure of what the error is related to. Do I explicitly need new line characters \n at the end of every line? How can I implement that? StringIO seems like it already has newline='\n' as a default parameter.
The key_file takes file path. It does not accept a file-like object.
The only way to provide in-memory key is using private_key "extra option" in connection specified by ssh_conn_id.

ESP32 firebase OAuth2.0 access token error -116

i'm trying to connect esp32 to firestore but an error appear on the serial monitor
Token info: type = OAuth2.0 access token, status = error
Token error: code: -116, message: mbedTLS, mbedtls_pk_parse_key: PK - Invalid key tag or value
i'm using source code from https://github.com/mobizt/Firebase-ESP-Client/blob/main/examples/Firestore/ImportDocuments/ImportDocuments.ino
Most likely you've not provided the private key string correctly (TLS libraries are rather picky about that), or the private key is not in correct format.
E.g. this is how you generate a 2048 bit RSA keypair in PKCS8 format (which is what the sample code appears to use):
$ ssh-keygen -t rsa -b 2048 -m PKCS8 -f testkey
This is how you add the resulting private key as a multiline raw string literal in C++:
const char PRIVATE_KEY[] = R"(-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDhhA52G0UQGFk5
+WDGpWXgVHR6Bjpyq81H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tsAz
dPxf+HcIxLsH7NrD7rzetMuAqyJoe16OCz0Ep6K1aEidB5OPv1WPw/wFNLF9uWb9
VpQhM23oCYC4kOhPiOq234UTJSSy6Z//6mHBZUyKISmmsgAfykzjCKL7YQKBgDNQ
qCXIhGVtpLDN4ybLyz7mqdYbjFiv4QdDYau1He8ZVbjfRCvnGmlDWmNXJgGRUjI2
F7A+WJw3+IfWHwwsozgO4QopCXuQu6N+90cK85Bu+mMXUWtzd1wqHRABv8MZTw5Y
+9mjB8oMgAUP84jcpFxRSiSunUCkuZc0JkqaQ/KrAoGAYxtl+555GpXK9eLfrVOG
02czqaXssGXIi31aGTICy7Esk8OgaG+pd4brcICeYE/CQ6gDjt6m/dHcw+DFmeFX
nVDHCIIDB9SeHM0Z3wZi/JruCtoB6vTxhA5lA9QeI4TpZvYXQkuerRUzRvhxyzkV
PrYun0MrVLxiiwezSTxlyGw=
-----END PRIVATE KEY-----
)";

Using GitBash Add - Commit - Push file to a GIT repository from WebApplication on Button Click

I have a requirement where I have to Add - Commit - Push 3 newly created Files into our Git Repository using GitBash commands on Button Click in a Web Application.
I have tried the following but in vain:
{
string gitCommand = "git bash";
string gitAddArgument = #"add -A" ;
string gitCommitArgument = #"commit""explanations_of_changes"" ";
string gitPushArgument = #"push our_remote";
Process.Start(gitCommand, gitAddArgument );
Process.Start(gitCommand, gitCommitArgument );
Process.Start(gitCommand, gitPushArgument );
}
On Button Click I need to Call the Git Bash Commands, Commit the 3 Files and then Push to Master Origin.
You have a few errors within your Git commands..
To add all files use: git add -A Note the capital A
To commit all modified files with a message use: git commit -a -m "Your message here"
To push your changes to remote use git push
To make your C# code complete:
{
string gitCommand = "git";
string gitAddArgument = "add -A" ;
string commitMessage = "Your commit message";
string gitCommitArgument = String.Format("commit -a -m \"{0}\"", commitMessage);
string gitPushArgument = "push";
Process.Start(gitCommand, gitAddArgument); // Runs: git add -A
Process.Start(gitCommand, gitCommitArgument); // Runs: git commit -a -m "Your commit message"
Process.Start(gitCommand, gitPushArgument); // Runs: git push
}
Note
Make sure the program git is within your PATH variabele else you wont be able to use it this way. If it's not in your PATH, use the absolute path to the git executeable
For example on linux it would be: /usr/bin/git this should be the text for gitCommand

How do I pass parameters to a jar file at the time of execution?

How do I pass parameters to a JAR file at the time of execution?
To pass arguments to the jar:
java -jar myjar.jar one two
You can access them in the main() method of "Main-Class" (mentioned in the manifest.mf file of a JAR).
String one = args[0];
String two = args[1];
The JAVA Documentation says:
java [ options ] -jar file.jar [
argument ... ]
and
... Non-option arguments after the
class name or JAR file name are passed
to the main function...
Maybe you have to put the arguments in single quotes.
You can do it with something like this, so if no arguments are specified it will continue anyway:
public static void main(String[] args) {
try {
String one = args[0];
String two = args[1];
}
catch (ArrayIndexOutOfBoundsException e){
System.out.println("ArrayIndexOutOfBoundsException caught");
}
finally {
}
}
And then launch the application:
java -jar myapp.jar arg1 arg2
java [ options ] -jar file.jar [ argument ... ]
if you need to pass the log4j properties file use the below option
-Dlog4j.configurationFile=directory/file.xml
java -Dlog4j.configurationFile=directory/file.xml -jar <JAR FILE> [arguments ...]
Incase arguments have spaces in it, you can pass like shown below.
java -jar myjar.jar 'first argument' 'second argument'

Resources