OPC UA PubSub SL 1.3 β€” UADP WriterGroup with assigned PSS.SecurityGroup still publishes plaintext

2026-06-22
4 days ago
  • alexschooneveld - 2026-06-22

    I am currently investigating an OPC UA PubSub connection over UDP. When I don't use encryption, the publish and subscribe are working correctly. But with encryption it does not.

    Environment

    OPC UA PubSub SL 1.3.0.0 (namespace UADP)
    OPC UA PubSub Security 1.3.0.0 (namespace PSS)
    OPC UA PubSub Base 1.3.0.0 (namespace PSB, incl. PSS.SecurityGroup / PSS.CONFIG)
    Programmatic PubSub in a CFC: UADP.Configuration β†’ UADP.Connection β†’ UADP.writerGroup β†’ UADP.writer β†’ writerDataSet, plus a CyclicCall gated by xEnable.

    Goal: publish secured UADP, SignAndEncrypt, policy PubSub-Aes256-CTR.

    What I do (one-shot, before xEnable := TRUE):
    fbSecurityGroup.SetInitialValue(
    'http://opcfoundation.org/UA/SecurityPolicy#PubSub-Aes256-CTR',
    PSB.SECURITY.SIGNING_AND_ENCRYPTION);
    stSecurityCfg := fbSecurityGroup.GetConfig(eErrorID => eError); // eError=NO_ERROR, udiEncryptionKeySize=32
    eError := fbSecurityGroup.SetSecurityKeys(udiTokenId, ADR(abyKey), SIZEOF(abyKey), 2436001000); // eError=NO_ERROR, SIZEOF=68
    // writerGroup.itfSecurityGroup := fbSecurityGroup -- set in the WriterGroup block's Parameters (a per-scan code write got overwritten)

    What I verified
    eError = NO_ERROR after both GetConfig and SetSecurityKeys; udiEncryptionKeySize = 32.
    Key length = 68 bytes (signing 32 β€– encrypt 32 β€– nonce 4).
    itfSecurityGroup is set via the WriterGroup's Parameters (so it isn't clobbered each scan).
    Init runs before xEnable (the writer doesn't run with xEnable=FALSE).
    The UADP.writerGroup FB exposes only itfSecurityGroup for security β€” no SecurityMode/MessageSecurityMode property.

    Result: the published datagrams are still plaintext β€” ExtendedFlags1 = 0x01 (security bit 0x10 clear), no security header:
    b1 01 29 00 0f 16 00 … (PublisherId 41, WriterGroupId 22, RawData, no security)

    Questions

    With UADP.writerGroup, is assigning a configured + keyed PSS.SecurityGroup to itfSecurityGroup sufficient to enable message security, or is there an additional step/property/method to switch the WriterGroup to SignAndEncrypt?
    At what point in the WriterGroup lifecycle is itfSecurityGroup read? Must it be assigned/keyed before xActive, and does the group need a stop→start to pick it up?
    Is there a required call order, and does SetSecurityKeys need to be called once or repeatedly?
    Should security be configured on the Connection/Configuration level rather than (or in addition to) the WriterGroup?
    Is there a working example of secured (SignAndEncrypt) programmatic UADP publishing with this library, or a known limitation in 1.3?
    How can I read back at runtime whether security is actually active (via itfDiagnostics or similar)?

    Additional information
    I can confirm that the consumer side works β€” i.e. a standard subscriber decrypts the same keys fine β€” so the keys/profile aren't the issue.
    The Wireshark capture of the published message is:
    0000 b1 01 29 00 0f 16 00 df 0d bb 25 01 00 0e 00 1b ..).......%.....
    0010 0e 00 00 00 00 00 00 00 ........

     
    πŸ‘
    1
  • YIN

    YIN - 4 days ago

    Your Wireshark capture is the clearest clue here. ExtendedFlags1 0x01 with the security bit clear means the writer is publishing with no security context at all, so the group is either never being consumed or it gets reset before the first datagram goes out. I have run into the same kind of thing with these function blocks before, where every call returns NO_ERROR and yet nothing on the wire changes, and in my case the order of events was the problem rather than the keys themselves.

    What I would check first is the exact moment the writer latches its inputs. You put itfSecurityGroup in Parameters, which is the right place, but if the writer's xEnable is already TRUE while the security group is still doing its one-shot init, or the writer runs its first cycle before SetSecurityKeys has returned NO_ERROR, it can start publishing unsecured and never pick the group up again. Try holding xEnable FALSE until GetConfig and SetSecurityKeys have both completed cleanly, and only then raise it once and watch ExtendedFlags1. If the security bit comes on, you know it was a sequencing thing and not the keys.

    SetSecurityKeys is a one-shot per token as far as I have seen, you don't need to call it every cycle, and the 68-byte layout you describe matches what your subscriber already accepts, so the key material looks fine. One more thing worth a look is whether anything re-initialises the writer group after your init, like a second call path or a re-enable on a mode change, since that would quietly drop the group again. For a runtime readback the wire is honestly the most reliable check you have, plus whatever error output the writer group exposes. I don't have that library version open in front of me so I can't swear to the diagnostics member names, but if the writer reports no error while the flag stays clear, that points at the group never being applied rather than a crypto failure.

    If the sequencing change doesn't help, comparing your call order against the secured PubSub example in the library package, if your install has one, would be my next step. And a practical note before you try this on a live controller: run it first in simulation or on a bench setup, and keep safety functions separate from anything like this, so a publishing test can't touch a running line.

     

Log in to post a comment.