How to assign a NULL value to an OID? - snmp

I have to make the code portable to work on 2 different devices where the length of the OID is just different by 1 byte. Therefore I am reusing the same struct to send the OIDs.
For device #1 I have
MIB[0]=0x2b
MIB[1]=0x06
MIB[2]=0x01
MIB[3]=0x02
MIB[4]=0x01
MIB[5]=0x02
MIB[6]=0x02
MIB[7]=0x01
MIB[8]=0x08
MIB[9]=0xA0
MIB[10]=0x00
For device #2 I have
MIB[0]=0x2b
MIB[1]=0x06
MIB[2]=0x01
MIB[3]=0x02
MIB[4]=0x01
MIB[5]=0x02
MIB[6]=0x02
MIB[7]=0x01
MIB[8]=0x08
MIB[9]=0x01
MIB[10]=???
How do I assign MIB[10] to be NULL, so that the OID that is sent will be 1.3.6.1.2.1.8.1 instead of 1.3.6.1.2.1.8.1.0 by sending MIB[10] = 0x00?

There is no representation for end-of-OID in the data; the length is encoded in the ASN.1 field used to transfer the OID, and this field needs to be replicated along with the OID (especially as you are using the serialized form anyway).

Related

Parse SNMP STRING in datacollection

I have an SNMP device that is return temperature as a string.
SNMPv2-SMI::enterprises.45501.1.3.8.0 = STRING: "+27.3"
Is there a way to parse out the value to persist it for graphing?
Hrm - you should be able to set the type to "octetstring" but I'm not sure about the "+" sign.
i.e.:
<group name="micro-instruments-temperature" ifType="all">
<mibObj oid=".1.3.6.1.4.1.45501.1.3.8" instance="0" alias="microTemp" type="octetstring"/>
</group>
Assign that group to a systemDef and see if it works. You can also make the instance a generic resource if needed.
Check out the "hwg.xml" file in the "datacollection" directory for a similar entry for an HWG temperature sensor (although I don't believe they sign the temperature value).

grape-api - Force empty string to set values to null

I am creating an API endpoint which contains a file upload field and a few string fields. My goal is to allow clients to clear values on those string fields, i.e. the DB should persist these values as null.
However, due to the fact that the request may contain files, the client should be setting the Content-type header to multipart/form-data. This implies that client cannot send a representation of "null", but can only send an empty string to indicate the intent of clearing the value for a given string field.
Is there a way for grape-api library to know that when it is receiving a multipart request it should be able to nullify blank string values in the params, or is there a better approach to what I am trying to achieve?
Grape.configure do |config|
config.param_builder = Grape::Extensions::Hashie::Mash::ParamBuilder
end
you can override the param builder. extend the default one and override the build_params method or monkey patch it.
params.transform_values {|v| v.eql?('') ? nil : v }

selecting a specific string from blob column

I have a table named as MSTCUSTOMERPROFILE haves a column ROLELIST which is of BLOB type. Now this BLOB haves data in xml format eg data...
<RoleListDTO>
<rolelist>
<RoleDTO>
<idEntity/>
<idEntityDesc/>
<userType>ECU</userType>
<userTypeDesc/>
<idRole>5</idRole>
<description>02A ENQUIRIES - ACCOUNT INFORMATION</description>
<idChannel>01</idChannel>
<idChannelDesc/>
<token/>
<datCreated/>
<createdBy/>
<datLastUpdated/>
<isDefaultRole>false</isDefaultRole>
<isDisplayCustProfile>false</isDisplayCustProfile>
<idcust/>
<typecust/>
<roleCreatebyUser>
<ListUserDTO>
<idEntity/>
<idEntityDesc/>
<userType/>
<userTypeDesc/>
<idChannel/>
<idChannelGroup/>
<idChannelDesc/>
<firstName/>
<lastName/>
<idChannelUser/>
<salutation/>
<idUser/>
<email/>
<isActive/>
<isProxyLocked/>
<isGroupFlag/>
<lockReason/>
<actDeactReason/>
</ListUserDTO>
</roleCreatebyUser>
</RoleDTO>
<RoleDTO>
<idEntity/>
<idEntityDesc/>
<userType>ECU</userType>
<userTypeDesc/>
<idRole>88</idRole>
<description>02C ENQUIRIES - CREDIT CARD DETAILS</description>
<idChannel>01</idChannel>
<idChannelDesc/>
<token/>
<datCreated/>
<createdBy/>
<datLastUpdated/>
<isDefaultRole>false</isDefaultRole>
<isDisplayCustProfile>false</isDisplayCustProfile>
<idcust/>
<typecust/>
<roleCreatebyUser>
<ListUserDTO>
<idEntity/>
<idEntityDesc/>
<userType/>
<userTypeDesc/>
<idChannel/>
<idChannelGroup/>
<idChannelDesc/>
<firstName/>
<lastName/>
<idChannelUser/>
<salutation/>
<idUser/>
<email/>
<isActive/>
<isProxyLocked/>
<isGroupFlag/>
<lockReason/>
<actDeactReason/>
</ListUserDTO>
</roleCreatebyUser>
</RoleDTO>
</rolelist>
<rmemail/>
</RoleListDTO>
I want to fetch the data inside <idRole> tag in the blob, in this case it being 88 i.e the result I want to fetch.
I need to do this by select query, is it possible in Oracle Database.? How ??
Take a look at the XML functions doc: https://docs.oracle.com/cd/E11882_01/server.112/e41084/functions002.htm#SQLRF51184
Something like EXTRACTVALUE
I have had a work around basically I wanted to do some logic based on a value in node in xml which happens to be inside this blob and wanted it in java. so I read the blob in java, into an byte array, made a DTO, a java class exactly with the same details and properties as the xml and nodes in it and populated it by using DTO unmarshalling logic, passed byte array and all.
So basically I did a workaround and its exactly not the answer I was looking for but it works.

JMS Correlation ID getting truncated

I am setting uuid field as JMSCorrelationID to my outbound message. I also set the reply to Queue and reply to Quemanger for getting COD. After setting correct user Identifier I am able to receive the COD message in the set ReplyTo Q. But the correlationID received in the COD message has truncated the bytes of my UUID field to 32 bytes. Due to this I cannot reconcile the message to which COD was received. Please find below code while sending the message. I have omitted the ReplyToQ and ReplytoQm part but it works as expected.
if(msgUuidId != null){
msg.setJMSCorrelationID(msgUuidId);
}
logger.info("Setting IBM_REPORT_COD");
msg.setIntProperty(JmsConstants.JMS_IBM_REPORT_COD, MQC.MQRO_COD);
logger.info("Setting JMS_IBM_MQMD_USERIDENTIFIER to :: "+ userid );
msg.setStringProperty(JmsConstants.JMS_IBM_MQMD_USERIDENTIFIER, userid);
I am also setting the MQMD Context on destination
((MQDestination) destination).setTargetClient(WMQConstants.WMQ_CLIENT_NONJMS_MQ);
((JmsDestination) destination).setBooleanProperty(WMQConstants.WMQ_MQMD_READ_ENABLED, true);
((JmsDestination) destination).setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);
((MQDestination) destination).setMQMDMessageContext(WMQConstants.WMQ_MDCTX_SET_IDENTITY_CONTEXT);
While receiving the message I am reading as follows:. I am using Mule API
String correlationID = (String)eventContext.getMessage().getInboundProperty("JMSCorrelationID");
So here I am observing that the value is truncated hex portion of uuid which I had set. Can someone please help me with this?
Shashi's comment rang a bell. As can be read here, MQ truncates JMSCorrelationId to 48 hex digits/24 bytes:
Note 1: The MQMD CorrelId field can hold a standard WebSphere MQ Correlation ID of 48 hexadecimal digits (24 bytes). The JMSCorrelationID can be a byte[] value, a string value containing hexadecimal characters and prefixed with "ID:", or an arbitrary string value not beginning "ID:". The first two of these represent a standard WebSphere MQ Correlation ID and map directly to or from the MQMD CorrelId field (truncated or padded with zeros as applicable); they do not use the MQRFH2 jms.Cid field. The third (arbitrary string) uses the MQRFH2 jms.Cid field; the first 24 bytes of the string, in UTF-8 format, are written into the MQMD CorrelID.
Does that correlate (pun intended) to the truncation you're seeing? If so, the pragmatic solution would be to use a 24 byte correlation ID.
Cheers,

Getting as3crypto to work with ruby (Gibberish/EzCrypto)

I'm trying to get as3crypto to play nice with either Gibberish or EzCrypto in AES-128 mode.
No matter what combination of settings I use I simply cannot get one to decrypt the other, and usually get a "bad decrypt" message in ruby. Each contained environment can decrypt data it encrypted itself but one cannot seem to decrypt the other.
Has anyone been able to get the two to work together?
Here's one of the variations I tried:
On the Actionscript side, using as3crypto:
//define the encryption key
var key:ByteArray = Hex.toArray("password");
//put plaintext into a bytearray
var plainText:ByteArray = Hex.toArray(Hex.fromString("this is a secret!"));
//set the encryption key
var aes:AESKey = new AESKey(key);
//encrypt the text
aes.encrypt( plainText );
trace(Base64.encode(Hex.fromArray(plainText)));
//encrypted value is N2QwZmI0YWQ4NzhmNDNhYjYzM2QxMTAwNGYzNDI1ZGUyMQ==
And on the ruby side, using gibberish:
// also tried the default size (256)
cipher = Gibberish::AES.new("password",128)
// raises the following exception: OpenSSL::Cipher::CipherError: wrong final block length
cipher.dec("N2QwZmI0YWQ4NzhmNDNhYjYzM2QxMTAwNGYzNDI1ZGUyMQ==")
I've tried all sort of different approaches, all yielding either the above exception or "bad encrypt"
Finally figured it out myself. The thing is both Gibberish and EzCrypto do not seem to provide a way to specify an IV, which is needed when using aes-cbc. The trick is to extract the iv from the first 16 bytes of the encrypted data as3crypto produces.
Here's the as3 code, which also changed a little:
// there are other ways to create the key, but this works well
var key:ByteArray = new ByteArray();
key.writeUTFBytes(MD5.encrypt("password"));
// encrypt the data. simple-aes-cbc is equiv. to aes-256-cbc in openssl/ruby, if your key is
// long enough (an MD5 is 32 bytes long)
var data:ByteArray = Hex.toArray(Hex.fromString("secret"));
var mode:ICipher= Crypto.getCipher("simple-aes-cbc", key) ;
mode.encrypt(data);
// the value here is base64, 32 bytes long. the first 16 bytes are the IV, needed to decrypt
// the data in ruby
// e.g: sEFOIF57LVGC+HMEI9EMTpcJdcu4J3qJm0PDdHE/OSY=
trace(Base64.encodeByteArray(data));
The ruby part uses a gem called encryptor to supply the iv.
you can also use OpenSSL directly, it's pretty straight forward:
key = Digest::MD5.hexdigest("password")
// decode the base64 encoded data back to binary:
encrypted_data = Base64.decode64("sEFOIF57LVGC+HMEI9EMTpcJdcu4J3qJm0PDdHE/OSY=")
// the tricky part: extract the IV from the decoded data
iv = encrypted_data.slice!(0,16)
// decrypt!
Encryptor.decrypt(encrypted_data,:key=>key,:iv=>iv)
// should output "secret"

Resources