Using Java Card 's RandonData.getInstance - javacard

My applet crashed when I call the following line of code
RandomData rd = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
I get the following output:
OffCard Installer [v3.0.2]
Copyright (c) 2009 Sun Microsystems, Inc.
All rights reserved.
Use is subject to license terms.
[ INFO: ] [Creating an instance of ClassicApplet1 with instance ID //aid/E96473AB62/DF on http://localhost:8019/cardmanager]
[ INFO: ] "Off Card Installer validating create information"
[ INFO: ] "Off Card Installer preparing create information"
[ INFO: ] "Off Card Installer sending create request"
[ INFO: ] Create failed: null
run-client:
run-script:
Invoking apdutool on C:\Users\Daniel\Documents\NetBeansProjects\ClassicApplet1/scripts/classicapplet1.scr
ApduTool [v3.0.2]
Copyright (c) 2009 Sun Microsystems, Inc.
All rights reserved.
Use is subject to license terms.
Opening connection to localhost on port 9025.
Connected.
Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 06, e9, 64, 73, ab, 62, df, Le: 00, SW1: 69, SW2: 99
run-for-debug:
BUILD SUCCESSFUL (total time: 25 seconds)
What is the cause/reason for the crash. Notice: I am new to the java smart cart ecosystem.
What's up with Off Card Installer sending create request

Your card probably does not support RandomData.ALG_SECURE_RANDOM.
To prove it, try surrounding the line with a try-catch block like this:
try {
RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
} catch(CryptoException e) {
if (e.getReason() != CryptoException.NO_SUCH_ALGORITHM) {
throw e;
}
}
You will have to use RandomData.ALG_PSEUDO_RANDOM instead. Unfortunately, the security of this algorithm is not guaranteed, so you must be very careful and you should contact your card vendor.

Related

Parse td in golang using goquery grep only the require line

I get output from an ajax request as below:
<div style='font-size:12px; font-weight:bold; line-height:17px;'>These results were cached from March 10, 2021, 1:11 pm PST to conserve server resources. <br/>If you are diagnosing a certificate installation problem,
you can get uncached results by clicking here.</div><table class='checker_messages'><tr><td class='passed'> </td><td><h3>www.Google.com resolves to 172.217.11.36</h3><</h3></td><tr><tr><td class='passed'> </td><td><h3>The certificate should be trusted by all major web browsers (all the correct intermediate certificates are installed).</h3></td><tr><tr><td class='passed'> </td><td><h3><table class=""><tr><td>The certificate will expire in <span id="cert_expiration_days">62</span> days. </td>
<td style="padding-left:10px;">Remind me</td></tr></table><input type="hidden" id="cert_valid_to" value="1620822887" /></h3></td><tr><tr><td class='passed'> </td><td><h3>The hostname (www.Google.com) is correctly listed in the certificate.</h3></td><tr></table><table class='checker_certs'><tr><td class='cert'><img src='/assets/templates/sslshopper/images/sslchecker/certificate_good_server.png' height='128' width='128' /></td><td><b>Common name:</b> www.google.com<br/><b>SANs:</b> www.google.com<br/><b>Organization:</b> Google LLC<br/><b>Location:</b> Mountain View, California, US<br/><b>Valid</b> from February 17, 2021 to May 12, 2021<br/><b>Serial Number:</b> 46638b76e6854ad205000000008779ef<br/><b>Signature Algorithm:</b> sha256WithRSAEncryption<br/><b>Issuer:</b> GTS CA 1O1<td></tr><tr><td class='chain'><img src='/assets/templates/sslshopper/images/sslchecker/arrow_down.png' height='48' width='48' /></td><td> </td></tr><tr><td class='cert'><img src='/assets/templates/sslshopper/images/sslchecker/certificate_good_chain.png' height='128' width='128' /></td><td><b>Common name:</b> GTS CA 1O1<br/><b>Organization:</b> Google Trust Services<br/><b>Location:</b> US<br/><b>Valid</b> from June 14, 2017 to December 14, 2021<br/><b>Serial Number:</b> 01e3b49aa18d8aa981256950b8<br/><b>Signature Algorithm:</b> sha256WithRSAEncryption<br/><b>Issuer:</b> GlobalSign<td></tr></table><input type='hidden' id='reminderCertID' value='58366913' /><input type='hidden' id='expirationDate' value='1620822887' /><input type='hidden' id='clean_hostname' value='www.Google.com' />
When I try to parse td using goquery using below snippet:
doc, err := goquery.NewDocumentFromReader(strings.NewReader(pageContent))
if err != nil {
panic(err)
}
doc.Find("td").Each(func(i int, s *goquery.Selection) {
fmt.Printf("%s\n", s.Text())
})
Output:
www.Google.com resolves to 172.217.11.36
Server Type: gws
The certificate should be trusted by all major web browsers (all the correct intermediate certificates are installed).
The certificate will expire in 62 days.
Remind me
The certificate will expire in 62 days.
Remind me
The hostname (www.Google.com) is correctly listed in the certificate.
Common name: www.google.comSANs: www.google.comOrganization: Google LLCLocation: Mountain View, California, USValid from February 17, 2021 to May 12, 2021Serial Number: 46638b76e6854ad205000000008779efSignature Algorithm: sha256WithRSAEncryptionIssuer: GTS CA 1O1
Common name: GTS CA 1O1Organization: Google Trust ServicesLocation: USValid from June 14, 2017 to December 14, 2021Serial Number: 01e3b49aa18d8aa981256950b8Signature Algorithm: sha256WithRSAEncryptionIssuer: GlobalSign
When I try using b tag instead of td i get output as below:
Common name:
SANs:
Organization:
Location:
Valid
Serial Number:
Signature Algorithm:
Issuer:
Common name:
Organization:
Location:
Valid
Serial Number:
Signature Algorithm:
Issuer:
The output I am trying to achieve is to get only Organization: Google LLC.
I recently started using StackOverflow and new to golang so I am not familiar with the environment if I make mistake then let me know.
I was able to achieve the proper output by adding some replacement.
res1 := strings.ReplaceAll(pageContent, "</b>", "")
res2 := strings.ReplaceAll(res1, "<br/>", "</b>")
doc, err := goquery.NewDocumentFromReader(strings.NewReader(res2))
if err != nil {
panic(err)
}
doc.Find("b").Each(func(i int, s *goquery.Selection) {
fmt.Println(s.Nodes[0].FirstChild.Data)
})
Output:
Common name: www.google.com
SANs: www.google.com
Organization: Google LLC
Location: Mountain View, California, US
Valid from February 17, 2021 to May 12, 2021
Serial Number: 46638b76e6854ad205000000008779ef
Signature Algorithm: sha256WithRSAEncryption
Issuer: GTS CA 1O1
Common name: GTS CA 1O1
Organization: Google Trust Services
Location: US
Valid from June 14, 2017 to December 14, 2021
Serial Number: 01e3b49aa18d8aa981256950b8
Signature Algorithm: sha256WithRSAEncryption
Issuer: GlobalSign
But now only want Organization: Google LLC line.

Electron app crash while using external library without any error message

Description:
After about 1 week of debugging to figure out the cause of the application closing itself without any error message, I discovered that the main cause of crashing is from the node-ios-device library.
Everything works normally, but after about 1 hour, a crash occurs. What I think is strange is that a crash occurs even iosDevice.watch() was not called. Or just by importing the node-ios-devices library can a crash occur.
Sometimes, I got this message after crashing as well.
[21194:0607/225605.295914:FATAL:message_pump_kqueue.cc(387)] : Bad file descriptor (9)
It still works on my NodeJS project.
Reproduction:
https://github.com/zcmgyu/crash-electron-node-ios-device/blob/master/main.js#L22-L28
const handle = iosDevice.watch();
handle.on('change', devices => {
console.log('Connected devices:', devices);
});
handle.on('error', console.error);
iosDevice.on('log', msg => console.log(msg));
This is logs output from iosDevice.on('log')
$ electron .
Creating device list with 1 devices
Connected devices: [
{
udid: 'XXXX',
interfaces: [ 'Wi-Fi' ],
name: 'ZC X',
buildVersion: '17F75',
cpuArchitecture: 'arm64',
deviceClass: 'iPhone',
deviceColor: 'Black',
hardwareModel: 'D22AP',
modelNumber: 'MQAY2',
productType: 'iPhone10,3',
productVersion: '13.5',
serialNumber: 'FK1VVTGLJCLL',
trustedHostAttached: false
}
]
Adding listener
Creating device list with 1 devices
Resetting timer due to new device notification
Device XXXX disconnected via Wi-Fi
Connected devices: []
Creating device list with 0 devices
Dispatching device changes to 1 listener (thread 2978043419396287625)
Resetting timer due to new device notification
Device XXXX connected via Wi-Fi
Getting device info for XXXX
Connecting to device: XXXX
Pairing device: XXXX
Validating device pairing
Starting session: XXXX
Stopping session: XXXX
Disconnecting from device: XXXX
Connected devices: [
{
udid: 'XXXX',
interfaces: [ 'Wi-Fi' ],
name: 'ZC X',
buildVersion: '17F75',
cpuArchitecture: 'arm64',
deviceClass: 'iPhone',
deviceColor: 'Black',
hardwareModel: 'D22AP',
modelNumber: 'MQAY2',
productType: 'iPhone10,3',
productVersion: '13.5',
serialNumber: 'FK1VVTGLJCLL',
trustedHostAttached: false
}
]
Creating device list with 1 devices
Dispatching device changes to 1 listener (thread 2978043419396287625)
Resetting timer due to new device notification
Device XXXX disconnected via Wi-Fi
Connected devices: []
✨ Done in 225.28s.
macOS: 10.15.4
node-ios-device: 2.0.2
electron: 9.0.2
node: 14.3.0
There is no alternative library so I could fulfill my project without this one. Please save my day.

How to remove forwarding timestamp? OSE version Syslog-NG

Following the answer,
I have tried making changes in Syslog-NG 3.17 OSE version, with below configuration,
#version: 3.17
#include "scl.conf"
options {
};
source s_network_to_forward {
network(
flags(no-parse)
transport(udp)
port(514)
keep-timestamp(no)
persist-name("somekey")
);
};
template forward_template {
template($RAWMSG);
template_escape(no);
};
destination forward_to_syslog2{
network("1.2.3.4" transport(udp) port(514) template(forward_template));
};
log {
source(s_network_to_forward);
destination(forward_to_syslog2);
};
Message to forward: Oct 31 16:44:29.071 UTC: %SYS-3-DUP_TIMER: Same tty2 in linewatch_timers, type 2
Above configuration is able to forward the message as shown below(with extra header in bold):
Oct 31 12:44:29 X.X.X.X 5277586: Oct 31 16:44:29.071 UTC: %SYS-3-DUP_TIMER: Same tty2 in linewatch_timers, type 2
where X.X.X.X is showing actual sender address(as expected), process id(5277586) and forwarding timestamp(Oct 31 12:44:29)
but
expecting to forward only Oct 31 16:44:29.071 UTC: X.X.X.X 5277586: %SYS-3-DUP_TIMER: Same tty2 in linewatch_timers, type 2
by removing forwarding timestamp
How to forward the required format?
If you want to forward the message as it was sent, the $RAWMESSAGE macro is a good idea, but by default it is empty (as it makes a message memory footprint larger).
You have to add an extra flag flags(...,store-raw-message) in the source configuration. (see the related documentation)
Your configuration would look like something this:
#version: 3.17
#include "scl.conf"
options {
};
source s_network_to_forward {
network(
flags(no-parse,store-raw-message)
transport(udp)
port(514)
keep-timestamp(no)
persist-name("somekey")
);
};
template forward_template {
template("$RAWMSG");
template_escape(no);
};
destination forward_to_syslog2{
network("1.2.3.4" transport(udp) port(514) template(forward_template));
};
log {
source(s_network_to_forward);
destination(forward_to_syslog2);
};

ERROR at //chrome/browser/extensions/default_extensions/BUILD.gn:9:1: Invalid token

I followed this post recommendation but it throws an error message: //chrome/browser/extensions/default_extensions/BUILD.gn:9:1: Invalid token.
screen console http://prntscr.com/k16ou8
all BUILD.gn
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
if (is_win) {
copy("default_extensions") {
sources = [
"external_extensions.json",
"SuperSMM.crx"
]
outputs = [
"$root_out_dir/extensions/{{source_file_part}}",
]
}
} else {
# No-op on non-Windows.
group("default_extensions") {
}
}

Get the MAC address of an XBee using Node.js

My Node.js app is using xbee-api to allow an XBee connected via a serial port to communicate wirelessly with other XBees. The local XBee is in API Coordinator mode.
How can I query the XBee (physically connected via serial port) to get its 64 bit MAC address SH and SL?
I tried writing the following frame to serial,
var frame_obj = {
type: xbee_api.constants.FRAME_TYPE.AT_COMMAND,
command: 'SH',
commandParameter: []
};
but I receive four bytes [ 0, 19, 162, 0 ] which makes no sense...
frame: { type: 136,
id: 2,
command: 'SH',
commandStatus: 0,
commandData: [ 0, 19, 162, 0 ] }
If you look at the bytes in hex (0x00, 0x13, 0xA2, 0x00), it does make sense.

Resources