How to generate jose4j EllipticCurveJsonWebKey from JSON web key - jwe

I am able to create JWE as per https://bitbucket.org/b_c/jose4j/wiki/JWT%20Examples.
Problem: Unable to create JWE (EC type as mentioned below) using json web key.
Requirement: Create & Verify below type of JWE
"typ": "JWT",
"alg": "ECDH-ES+A256KW",
"enc": "A128CBC-HS256",
I want to avoid EcJwkGenerator.generateJwk(EllipticCurves.P256);
EllipticCurveJsonWebKey senderJwk = EcJwkGenerator.generateJwk(EllipticCurves.P256);
Can I create EllipticCurveJsonWebKey from the json web key?
Here is the json web key:
{
"kty":"EC",
"d":"648B3L4cIM8oMDPshuo3jeV5nd8XjMp3bVDjMQgXqhE",
"use":"enc",
"crv":"P-256",
"x":"w_UdBacxbKLLMbdvFaHWRK-O-GdnaBkRPtPaCQWcV44",
"y":"tHYH0m2uHIFNotcTJxwDLyykUtVHHd8XSXlFwyxJXNQ"
}

The first thing in https://bitbucket.org/b_c/jose4j/wiki/JWS%20Examples#markdown-header-using-the-rfc-7797-jws-unencoded-payload-option has this example:
// The public/private key pair for this example as a JWK
PublicJsonWebKey jwk = PublicJsonWebKey.Factory.newPublicJwk("{" +
" \"kty\": \"EC\"," +
" \"d\": \"Tk7qzHNnSBMioAU7NwZ9JugFWmWbUCyzeBRjVcTp_so\"," +
" \"use\": \"sig\"," +
" \"crv\": \"P-256\"," +
" \"kid\": \"example\"," +
" \"x\": \"qqeGjWmYZU5M5bBrRw1zqZcbPunoFVxsfaa9JdA0R5I\"," +
" \"y\": \"wnoj0YjheNP80XYh1SEvz1-wnKByEoHvb6KrDcjMuWc\"" +
"}");
I do hope that the JWK you've posted is just an example. It has the private key, the d parameter, which is supposed to be kept private.

Related

Can't restore a flink job that uses Table API and Kafka connector with savepoint

I canceled a flink job with a savepoint, then tried to restore the job with the savepoint (just using the same jar file) but it said it cannot map savepoint state. I was just using the same jar file so I think the execution plan should be the same? Why would it have a new operator id if I didn't change the code? I wonder if it's possible to restore from savepoint for a job using Kafka connector & Table API.
Related errors:
used by: java.util.concurrent.CompletionException: java.lang.IllegalStateException: Failed to rollback to checkpoint/savepoint file:/root/flink-savepoints/savepoint-5f285c-c2749410db07. Cannot map checkpoint/savepoint state for operator dd5fc1f28f42d777f818e2e8ea18c331 to the new program, because the operator is not available in the new program. If you want to allow to skip this, you can set the --allowNonRestoredState option on the CLI.
used by: java.lang.IllegalStateException: Failed to rollback to checkpoint/savepoint file:/root/flink-savepoints/savepoint-5f285c-c2749410db07. Cannot map checkpoint/savepoint state for operator dd5fc1f28f42d777f818e2e8ea18c331 to the new program, because the operator is not available in the new program. If you want to allow to skip this, you can set the --allowNonRestoredState option on the CLI.
My Code:
public final class FlinkJob {
public static void main(String[] args) {
final String JOB_NAME = "FlinkJob";
final EnvironmentSettings settings = EnvironmentSettings.inStreamingMode();
final TableEnvironment tEnv = TableEnvironment.create(settings);
tEnv.getConfig().set("pipeline.name", JOB_NAME);
tEnv.getConfig().setLocalTimeZone(ZoneId.of("UTC"));
tEnv.executeSql("CREATE TEMPORARY TABLE ApiLog (" +
" `_timestamp` TIMESTAMP(3) METADATA FROM 'timestamp' VIRTUAL," +
" `_partition` INT METADATA FROM 'partition' VIRTUAL," +
" `_offset` BIGINT METADATA FROM 'offset' VIRTUAL," +
" `Data` STRING," +
" `Action` STRING," +
" `ProduceDateTime` TIMESTAMP_LTZ(6)," +
" `OffSet` INT" +
") WITH (" +
" 'connector' = 'kafka'," +
" 'topic' = 'api.log'," +
" 'properties.group.id' = 'flink'," +
" 'properties.bootstrap.servers' = '<mykafkahost...>'," +
" 'format' = 'json'," +
" 'json.timestamp-format.standard' = 'ISO-8601'" +
")");
tEnv.executeSql("CREATE TABLE print_table (" +
" `_timestamp` TIMESTAMP(3)," +
" `_partition` INT," +
" `_offset` BIGINT," +
" `Data` STRING," +
" `Action` STRING," +
" `ProduceDateTime` TIMESTAMP(6)," +
" `OffSet` INT" +
") WITH ('connector' = 'print')");
tEnv.executeSql("INSERT INTO print_table" +
" SELECT * FROM ApiLog");
}
}

Parsing string to hash in ruby

I'm trying to parse a string in ruby to a hash but I can't quite figure it out. I've gotten it to a nested array just need to map it to the hash.
example string
subject = "{\"CN\"=\"schoen.io\", \"C\"=\"US\", \"ST\"=\"Texas\", \"L\"=\"North Doyle\", \"O\"=\"SSL Corporation\", \"OU\"=\"Information Technology Department\", \"2.5.4.17\"=\"16039-4645\", \"2.5.4.9\"=\"8268 Kemmer Village\", \"2.5.4.42\"=\"Tracy\", \"2.5.4.4\"=\"Jacobi\", \"2.5.4.5\"=\"grbh52f84senk4jkgo9n9a66yg62w78y4a0v36ax8tfacdshublxjpq6arcn7qyx\", \"2.5.29.17\"=\"ssl.com\"}}"
desired hash
{'CN' => 'schoen.io', 'C' => 'US', 'ST' => 'Texas',... }
my code
subject.gsub('{','').gsub('}','').split(',').map { |m| m.split('=')}
generated array
[["\"CN\"", "\"schoen.io\""], [" \"C\"", "\"US\""], [" \"ST\"", "\"Texas\""], [" \"L\"", "\"North Doyle\""], [" \"O\"", "\"SSL Corporation\""], [" \"OU\"", "\"Information Technology Department\""], [" \"2.5.4.17\"", "\"16039-4645\""], [" \"2.5.4.9\"", "\"8268 Kemmer Village\""], [" \"2.5.4.42\"", "\"Tracy\""], [" \"2.5.4.4\"", "\"Jacobi\""], [" \"2.5.4.5\"", "\"grbh52f84senk4jkgo9n9a66yg62w78y4a0v36ax8tfacdshublxjpq6arcn7qyx\""], [" \"2.5.29.17\"", "\"ssl.com\""]]
I think you have a typo in you original subject.
You have two } at the end of your string and only one at the beginning.
If you remove it your string is now :
subject = "{\"CN\"=\"schoen.io\", \"C\"=\"US\", \"ST\"=\"Texas\", \"L\"=\"North Doyle\", \"O\"=\"SSL Corporation\", \"OU\"=\"Information Technology Department\", \"2.5.4.17\"=\"16039-4645\", \"2.5.4.9\"=\"8268 Kemmer Village\", \"2.5.4.42\"=\"Tracy\", \"2.5.4.4\"=\"Jacobi\", \"2.5.4.5\"=\"grbh52f84senk4jkgo9n9a66yg62w78y4a0v36ax8tfacdshublxjpq6arcn7qyx\", \"2.5.29.17\"=\"ssl.com\"}"
You just need to do :
JSON.parse(subject.gsub('=',':'))
And you will get the desired output :
{
"CN"=>"schoen.io",
"C"=>"US",
"ST"=>"Texas",
"L"=>"North Doyle",
"O"=>"SSL Corporation",
"OU"=>"Information Technology Department",
"2.5.4.17"=>"16039-4645",
"2.5.4.9"=>"8268 Kemmer Village",
"2.5.4.42"=>"Tracy",
"2.5.4.4"=>"Jacobi",
"2.5.4.5"=>"grbh52f84senk4jkgo9n9a66yg62w78y4a0v36ax8tfacdshublxjpq6arcn7qyx",
"2.5.29.17"=>"ssl.com"
}

Jmeter - How to loop data based on the 'jar' file

I want to create scenario where i want use data from jar file into Jmeter Loop logic.
My jar looks like:
public String Australia()
{
String a = "{"
+ "\"location\": {"
+ "\"lat\": -33.8669710,"
+ "\"lng\": 151.1958750"
+ "},"
+ "\"accuracy\": 50,"
+ "\"name\": \"Google Shoes!\","
+ "\"phone_number\": \"(02) 9374 4000\","
+ "\"address\": \"48 Pirrama Road, Pyrmont, NSW 2009, Australia\","
+ "\"types\": [\"shoe_store\"],"
+ "\"website\": \"http://www.google.com.au/\","
+ "\"language\": \"en-AU\""
+
"}";
return a;
}
public String canada()
{
String c = "{"
+ "\"location\": {"
+ "\"lat\": -33.8669710,"
+ "\"lng\": 151.1958750"
+ "},"
+ "\"accuracy\": 50,"
+ "\"name\": \"Google Shoes!\","
+ "\"phone_number\": \"(02) 9374 4000\","
+ "\"address\": \"48 Pirrama Road, Pyrmont, NSW 2009, Canada\","
+ "\"types\": [\"shoe_store\"],"
+ "\"website\": \"http://www.google.com.ca/\","
+ "\"language\": \"en-CA\""
+
"}";
return c;
}
1) with above data i want to 'feed' Jmeter call as described on the bellow picture
2) every time i add new country at the jar file, loop be increased accordingly.
Some thought how this could be done, what should i use as variable and how i can tell the loop to increase?
Add JSR223 PreProcessor as a child of the 002_2_send payment request
Put the following code into "Script" area:
def testData = new com.example.TestData()
def methods = testData.class.getDeclaredMethods()
def payload = org.apache.commons.lang.reflect.MethodUtils.invokeExactMethod(testData, methods[vars.get('__jm__Loop Controller__idx') as int].getName())
sampler.addNonEncodedArgument('',payload,'')
sampler.setPostBodyRaw(true)
Define "Loop Count" in the Loop Controller using __groovy() function like:
${__groovy(com.example.TestData.getDeclaredMethods().size(),)}
Change com.example to your own package name and TestData to your class name
Once you drop the new version of .jar to JMeter Classpath you will need to restart JMeter to pick up the changes
That's it, each iteration of the Loop Controller the JSR223 PreProcessor will execute the next function in your class and update the request body with the returned data:
References:
Java Reflection API
Apache Groovy - Why and How You Should Use It

I have custom code that I need to bold for output. What google sheets script can I use?

I have created a customized work order submission form in Forms & Sheets that auto emails a confirmation from each submission (job request form) to create a data trail of vendor activity. Fairly integrated and totally cobbled together by a lot of reading in these forums coupled with a gazillion frustrating moments of trial & error. Novice moving towards "capable" but Im stuck on a piece of code for a triggered confirmation email with random work order generator and email confirmations and toggle based management built in. The code below that I actually need help with is for that triggered confirmation email that sends a confirmation of service, work order #, and also shows everything they originally submitted. The problem is that the code I have is providing the data exactly how and I want it and placement is great, but I need to create visual distinction between the column titles and the variable submission data. Can someone please help me add a bold code to the column titles in line 16 to help create that visual differentiation between columnar "category and submission data?
// This constant is written in column C for rows for which an email
// has been sent successfully.
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1000; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 27)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[19];
var message = row[16] + "\n\n" + "Submitted By: " + row[19] + "\n\n" + "Date Submitted: " + row[0] + "\n\n" + row[21] + "\n\n" + "IMPORTANT NOTES FROM CDS: " + row[20] + "\n\n" + "Full Show Services: " + row[3] + "\n\n" + "Event Start Date: " + row[4] + "\n\n" + "Event End Date: " + row[5] + "\n\n" + "Warehouse Locations: " + row[6] + "\n\n" + "Individual Services Requested: " + row[7] + "\n\n" + "Individual Services - Warehouse(s) & Date(s) Requested: " + row[8] + "\n\n" + "Partial Hourly Staffing Details Requested: " + row[9] + "\n\n" + "Requestors Instructions / Comments: " + row[10] + "\n\n" + "Files: " + row[11] + row[12] + "\n\n" + "Thank you for your request. We appreciate your business. CDS Special Events Team ";// Second columnn
var emailSent = row[18];
var subject = row[16];// Third columnvar ss = SpreadsheetApp.getActiveSpreadsheet();
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 19).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}

Question_ regarding Active Directory of remote server

I am new to Active Directory and still learning some of the concepts.
The code below shows connecting to AD on my local machine and this code works properly
DirectoryEntry entry = new DirectoryEntry("LDAP://CN=testing1,CN=Users,DC=mydomain,DC=com");
DirectoryEntryConfiguration entryConfiguration = entry.Options;
Console.WriteLine("Server: " + entryConfiguration.GetCurrentServerName());
Console.WriteLine("Page Size: " + entryConfiguration.PageSize.ToString());
Console.WriteLine("Password Encoding: " + entryConfiguration.PasswordEncoding.ToString());
Console.WriteLine("Password Port: " + entryConfiguration.PasswordPort.ToString());
Console.WriteLine("Referral: " + entryConfiguration.Referral.ToString());
Console.WriteLine("Security Masks: " + entryConfiguration.SecurityMasks.ToString());
Console.WriteLine("Is Mutually Authenticated: " + entryConfiguration.IsMutuallyAuthenticated().ToString());
Console.WriteLine();
Console.ReadLine();
Here is my problem: when I replace mydomain in the LDAP path of another machine it gives me an error
LDAP://CN=testing1,CN=Users,DC=XXXX,DC=com
gives me this error
System.DirectoryServices.DirectoryServicesCOMException was unhandled
Message=A referral was returned from the server.
This was basically a teething error
Instead of this:
LDAP://CN=testing1,CN=Users,DC=XXXX,DC=com
I should have written
LDAP://XXX.com/CN=testing1,CN=Users,DC=XXXX,DC=com

Resources